diff options
author | Matt Broadstone <mbroadst@mongodb.com> | 2022-02-01 14:55:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-01 16:12:55 +0000 |
commit | 1cc5df724ab48604e19a8b2f3703563c553b1ba0 (patch) | |
tree | 68493e81ddd2bc3fc790dd626ad2de689fef405c /src/mongo/s/catalog/sharding_catalog_client_impl.cpp | |
parent | b2098c676bdc64e3194734fa632b133c47496646 (diff) | |
download | mongo-1cc5df724ab48604e19a8b2f3703563c553b1ba0.tar.gz |
SERVER-62609 Represent the w parameter of WriteConcernOptions as a variant
Diffstat (limited to 'src/mongo/s/catalog/sharding_catalog_client_impl.cpp')
-rw-r--r-- | src/mongo/s/catalog/sharding_catalog_client_impl.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp index 80a826bfbc9..bf1bd427744 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp @@ -811,8 +811,18 @@ Status ShardingCatalogClientImpl::runUserManagementWriteCommand(OperationContext } writeConcern = sw.getValue(); - if ((writeConcern.wNumNodes != 1) && - (writeConcern.wMode != WriteConcernOptions::kMajority)) { + auto isValidUserManagementWriteConcern = stdx::visit( + [](auto&& arg) { + using T = std::decay_t<decltype(arg)>; + if constexpr (std::is_same_v<T, std::string>) + return arg == WriteConcernOptions::kMajority; + else if constexpr (std::is_same_v<T, int64_t>) + return arg == 1; + return false; + }, + writeConcern.w); + + if (!isValidUserManagementWriteConcern) { return {ErrorCodes::InvalidOptions, str::stream() << "Invalid replication write concern. User management write " "commands may only use w:1 or w:'majority', got: " @@ -820,8 +830,7 @@ Status ShardingCatalogClientImpl::runUserManagementWriteCommand(OperationContext } } - writeConcern.wMode = WriteConcernOptions::kMajority; - writeConcern.wNumNodes = 0; + writeConcern.w = WriteConcernOptions::kMajority; BSONObjBuilder modifiedCmd; if (!initialCmdHadWriteConcern) { @@ -895,9 +904,9 @@ Status ShardingCatalogClientImpl::applyChunkOpsDeprecated(OperationContext* opCt const ChunkVersion& lastChunkVersion, const WriteConcernOptions& writeConcern, repl::ReadConcernLevel readConcern) { - invariant(serverGlobalParams.clusterRole == ClusterRole::ConfigServer || - (readConcern == repl::ReadConcernLevel::kMajorityReadConcern && - writeConcern.wMode == WriteConcernOptions::kMajority)); + invariant( + serverGlobalParams.clusterRole == ClusterRole::ConfigServer || + (readConcern == repl::ReadConcernLevel::kMajorityReadConcern && writeConcern.isMajority())); BSONObj cmd = BSON("applyOps" << updateOps << "preCondition" << preCondition << WriteConcernOptions::kWriteConcernField << writeConcern.toBSON()); |