diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2017-11-17 14:43:21 -0500 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2017-11-21 15:31:03 -0500 |
commit | 43efeb64565f7e3d0d55b5a647fe11e92aa3dc67 (patch) | |
tree | 3b61c2f61815b2a9142575e6b3d2833d10ba2249 /src/mongo/s/catalog | |
parent | 7bfb336f59febbaabb4735dfda49b490e6d98792 (diff) | |
download | mongo-43efeb64565f7e3d0d55b5a647fe11e92aa3dc67.tar.gz |
SERVER-31866 setFCV should always wait for majority writeConcern
Diffstat (limited to 'src/mongo/s/catalog')
4 files changed, 22 insertions, 5 deletions
diff --git a/src/mongo/s/catalog/sharding_catalog_manager.cpp b/src/mongo/s/catalog/sharding_catalog_manager.cpp index b9808971703..1c0b2f0ffc7 100644 --- a/src/mongo/s/catalog/sharding_catalog_manager.cpp +++ b/src/mongo/s/catalog/sharding_catalog_manager.cpp @@ -313,7 +313,7 @@ Status ShardingCatalogManager::_initConfigIndexes(OperationContext* opCtx) { } Status ShardingCatalogManager::setFeatureCompatibilityVersionOnShards(OperationContext* opCtx, - const std::string& version) { + const BSONObj& cmdObj) { // No shards should be added until we have forwarded featureCompatibilityVersion to all shards. Lock::SharedLock lk(opCtx->lockState(), _kShardMembershipLock); @@ -331,7 +331,7 @@ Status ShardingCatalogManager::setFeatureCompatibilityVersionOnShards(OperationC opCtx, ReadPreferenceSetting{ReadPreference::PrimaryOnly}, "admin", - BSON(FeatureCompatibilityVersion::kCommandName << version), + cmdObj, Shard::RetryPolicy::kIdempotent); if (!response.isOK()) { return response.getStatus(); diff --git a/src/mongo/s/catalog/sharding_catalog_manager.h b/src/mongo/s/catalog/sharding_catalog_manager.h index c0c0ae2c605..cd36a69cbfe 100644 --- a/src/mongo/s/catalog/sharding_catalog_manager.h +++ b/src/mongo/s/catalog/sharding_catalog_manager.h @@ -304,8 +304,7 @@ public: /** * Runs the setFeatureCompatibilityVersion command on all shards. */ - Status setFeatureCompatibilityVersionOnShards(OperationContext* opCtx, - const std::string& version); + Status setFeatureCompatibilityVersionOnShards(OperationContext* opCtx, const BSONObj& cmdObj); // // For Diagnostics diff --git a/src/mongo/s/catalog/sharding_catalog_manager_collection_operations.cpp b/src/mongo/s/catalog/sharding_catalog_manager_collection_operations.cpp index 90f54be2fe6..812110d838a 100644 --- a/src/mongo/s/catalog/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/s/catalog/sharding_catalog_manager_collection_operations.cpp @@ -45,6 +45,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" #include "mongo/db/query/collation/collator_factory_interface.h" +#include "mongo/db/repl/repl_client_info.h" #include "mongo/executor/task_executor.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/balancer_configuration.h" @@ -338,6 +339,18 @@ void ShardingCatalogManager::generateUUIDsForExistingShardedCollections(Operatio )) .docs; + if (shardedColls.empty()) { + LOG(0) << "all sharded collections already have UUIDs"; + + // We did a local read of the collections collection above and found that all sharded + // collections already have UUIDs. However, the data may not be majority committed (a + // previous setFCV attempt may have failed with a write concern error). Since the current + // Client doesn't know the opTime of the last write to the collections collection, make it + // wait for the last opTime in the system when we wait for writeConcern. + repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx); + return; + } + // Generate and persist a new UUID for each collection that did not have a UUID. LOG(0) << "generating UUIDs for " << shardedColls.size() << " sharded collections that do not yet have a UUID"; diff --git a/src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp b/src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp index 38b8295e1c9..97a28b4a3b1 100644 --- a/src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp +++ b/src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp @@ -660,7 +660,12 @@ StatusWith<std::string> ShardingCatalogManager::addShard( return batchResponseStatus; } - // The featureCompatibilityVersion should be the same throughout the cluster. + // The featureCompatibilityVersion should be the same throughout the cluster. We don't + // explicitly send writeConcern majority to the added shard, because a 3.4 mongod will reject + // it (setFCV did not support writeConcern until 3.6), and a 3.6 mongod will still default to + // majority writeConcern. + // + // TODO SERVER-32045: propagate the user's writeConcern auto versionResponse = _runCommandForAddShard( opCtx, targeter.get(), |