summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2018-02-23 11:50:59 -0500
committerEsha Maharishi <esha.maharishi@mongodb.com>2018-02-23 13:54:44 -0500
commitbaef1f98322ce6a602a645c87691f19abf8257e8 (patch)
tree1c2ca287ff16920f32473d6d9eb7c99f683eca39
parent9509aaa557ed26d789efa98f0ff8addf1814fb87 (diff)
downloadmongo-baef1f98322ce6a602a645c87691f19abf8257e8.tar.gz
SERVER-33465 forward-port handling upgrade/downgrade states when sending setFCV to new shard in addShard
-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();
}