summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
index ec37ae9e83e..79489af4c9e 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
@@ -659,18 +659,29 @@ StatusWith<std::string> ShardingCatalogManager::addShard(
return batchResponseStatus;
}
- // 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.
+
+ // Since addShard runs under the fcvLock, it is guaranteed the fcv state won't change, but it's
+ // possible an earlier setFCV failed partway, so we handle all possible fcv states. Note, if
+ // the state is upgrading (downgrading), a user cannot switch to downgrading (upgrading) without
+ // first finishing the upgrade (downgrade).
//
- // TODO SERVER-32045: propagate the user's writeConcern
- auto versionResponse = _runCommandForAddShard(
- opCtx,
- targeter.get(),
- "admin",
- BSON(FeatureCompatibilityVersion::kCommandName << FeatureCompatibilityVersion::toString(
- serverGlobalParams.featureCompatibility.getVersion())));
+ // Note, 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.
+ BSONObj setFCVCmd;
+ switch (serverGlobalParams.featureCompatibility.getVersion()) {
+ case ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo40:
+ case ServerGlobalParams::FeatureCompatibility::Version::kUpgradingTo40:
+ setFCVCmd = BSON(FeatureCompatibilityVersion::kCommandName
+ << FeatureCompatibilityVersionCommandParser::kVersion40);
+ break;
+ default:
+ setFCVCmd = BSON(FeatureCompatibilityVersion::kCommandName
+ << FeatureCompatibilityVersionCommandParser::kVersion36);
+ break;
+ }
+ auto versionResponse = _runCommandForAddShard(opCtx, targeter.get(), "admin", setFCVCmd);
if (!versionResponse.isOK()) {
return versionResponse.getStatus();
}