|
| 1 | +/* |
| 2 | + * Copyright 2025-Present Couchbase, Inc. |
| 3 | + * |
| 4 | + * Use of this software is governed by the Business Source License included |
| 5 | + * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified |
| 6 | + * in that file, in accordance with the Business Source License, use of this |
| 7 | + * software will be governed by the Apache License, Version 2.0, included in |
| 8 | + * the file licenses/APL2.txt. |
| 9 | + */ |
| 10 | + |
| 11 | +#include "set_param_command_context.h" |
| 12 | +#include "engine_wrapper.h" |
| 13 | +#include <daemon/buckets.h> |
| 14 | +#include <daemon/concurrency_semaphores.h> |
| 15 | +#include <daemon/connection.h> |
| 16 | +#include <logger/logger.h> |
| 17 | +#include <memcached/engine.h> |
| 18 | + |
| 19 | +EngineParamCategory SetParamCommandContext::getParamCategory(Cookie& cookie) { |
| 20 | + const auto& req = cookie.getRequest(); |
| 21 | + using cb::mcbp::request::SetParamPayload; |
| 22 | + const auto& payload = req.getCommandSpecifics<SetParamPayload>(); |
| 23 | + switch (payload.getParamType()) { |
| 24 | + case SetParamPayload::Type::Flush: |
| 25 | + return EngineParamCategory::Flush; |
| 26 | + case SetParamPayload::Type::Checkpoint: |
| 27 | + return EngineParamCategory::Checkpoint; |
| 28 | + case SetParamPayload::Type::Dcp: |
| 29 | + return EngineParamCategory::Dcp; |
| 30 | + case SetParamPayload::Type::Vbucket: |
| 31 | + return EngineParamCategory::Vbucket; |
| 32 | + case SetParamPayload::Type::Replication: |
| 33 | + Expects(false && "mcbp_validator should reject this group"); |
| 34 | + } |
| 35 | + throw std::invalid_argument( |
| 36 | + "SetParamCommandContext::getParamCategory(): Invalid param " |
| 37 | + "provided: " + |
| 38 | + std::to_string(int(payload.getParamType()))); |
| 39 | +} |
| 40 | + |
| 41 | +SetParamCommandContext::SetParamCommandContext(Cookie& cookie) |
| 42 | + : SteppableCommandContext(cookie), |
| 43 | + category(getParamCategory(cookie)), |
| 44 | + key(cookie.getRequest().getKeyString()), |
| 45 | + value(cookie.getRequest().getValueString()), |
| 46 | + vbid(cookie.getRequest().getVBucket()) { |
| 47 | +} |
| 48 | + |
| 49 | +cb::engine_errc SetParamCommandContext::step() { |
| 50 | + cb::engine_errc ret = cb::engine_errc::success; |
| 51 | + try { |
| 52 | + ret = bucket_set_parameter(cookie, category, key, value, vbid); |
| 53 | + } catch (const std::exception& e) { |
| 54 | + LOG_WARNING_CTX("SetParamCommandContext: ", |
| 55 | + {"conn_id", cookie.getConnectionId()}, |
| 56 | + {"error", e.what()}); |
| 57 | + } |
| 58 | + if (ret == cb::engine_errc::success) { |
| 59 | + cookie.sendResponse(ret); |
| 60 | + } |
| 61 | + return ret; |
| 62 | +} |
0 commit comments