diff options
Diffstat (limited to 'src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp')
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp | 91 |
1 files changed, 55 insertions, 36 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 f03ee603838..d10ba0288d3 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 @@ -84,6 +84,7 @@ using CallbackHandle = executor::TaskExecutor::CallbackHandle; using CallbackArgs = executor::TaskExecutor::CallbackArgs; using RemoteCommandCallbackArgs = executor::TaskExecutor::RemoteCommandCallbackArgs; using RemoteCommandCallbackFn = executor::TaskExecutor::RemoteCommandCallbackFn; +using FeatureCompatibilityParams = ServerGlobalParams::FeatureCompatibility; const ReadPreferenceSetting kConfigReadSelector(ReadPreference::Nearest, TagSet{}); @@ -338,23 +339,24 @@ StatusWith<ShardType> ShardingCatalogManager::_validateHostAsShard( << "field when attempting to add " << connectionString.toString() << " as a shard"); } + const auto currentFcv = serverGlobalParams.featureCompatibility.getVersion(); // (Generic FCV reference): These FCV checks should exist across LTS binary versions. - if (serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo( - ServerGlobalParams::FeatureCompatibility::kLatest) || - serverGlobalParams.featureCompatibility.isUpgradingOrDowngrading()) { - // If the cluster's FCV is kLatest, or upgrading to / downgrading from, the node being added - // must be a version kLatest binary. + if (currentFcv == FeatureCompatibilityParams::kLatest || + currentFcv == FeatureCompatibilityParams::kDowngradingFromLatestToLastContinuous || + currentFcv == FeatureCompatibilityParams::kDowngradingFromLatestToLastLTS || + currentFcv == FeatureCompatibilityParams::kUpgradingFromLastContinuousToLatest || + currentFcv == FeatureCompatibilityParams::kUpgradingFromLastLTSToLatest) { + // If the cluster's FCV is kLatest, or upgrading to / downgrading from kLatest, the node + // being added must be a version kLatest binary. invariant(maxWireVersion == WireVersion::LATEST_WIRE_VERSION); - } else if (serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo( - ServerGlobalParams::FeatureCompatibility::kLastContinuous)) { - // If we are using the kLastContinuous FCV, the node being added must be of the - // last-continuous or latest binary version. + } else if (currentFcv == FeatureCompatibilityParams::kLastContinuous || + currentFcv == FeatureCompatibilityParams::kUpgradingFromLastLTSToLastContinuous) { + // If we are using the kLastContinuous or upgrading to kLastContinuous FCV, the node being + // added must be of the last-continuous or latest binary version. invariant(maxWireVersion >= WireVersion::LAST_CONT_WIRE_VERSION); } else { - // If we are using the kLastLTS FCV, the node being added must be of the last-lts or latest - // binary version. - invariant(maxWireVersion == WireVersion::LAST_LTS_WIRE_VERSION || - maxWireVersion == WireVersion::LATEST_WIRE_VERSION); + // (Generic FCV reference): These FCV checks should exist across LTS binary versions. + invariant(currentFcv == FeatureCompatibilityParams::kLastLTS); } // Check whether there is a master. If there isn't, the replica set may not have been @@ -656,32 +658,49 @@ StatusWith<std::string> ShardingCatalogManager::addShard( invariant(!opCtx->lockState()->isLocked()); Lock::SharedLock lk(opCtx->lockState(), FeatureCompatibilityVersion::fcvLock); - BSONObjBuilder setFCVBuilder; - // (Generic FCV reference): These FCV checks should exist across LTS binary versions. - switch (serverGlobalParams.featureCompatibility.getVersion()) { - case ServerGlobalParams::FeatureCompatibility::kLatest: - case ServerGlobalParams::FeatureCompatibility::Version::kUpgradingFrom44To47: { - SetFeatureCompatibilityVersion setLatestCmd( - ServerGlobalParams::FeatureCompatibility::kLatest); - // The serialize function generated by IDL requires the DB name to be set. - setLatestCmd.setDbName(NamespaceString::kAdminDb); - setLatestCmd.serialize({}, &setFCVBuilder); - break; - } - default: + // Get the target version that the newly added shard should be set to. + const FeatureCompatibilityParams::Version setVersion = [] { + const auto currentFcv = serverGlobalParams.featureCompatibility.getVersion(); + // (Generic FCV reference): These FCV checks should exist across LTS binary versions. + if (currentFcv == FeatureCompatibilityParams::kLatest || + currentFcv == FeatureCompatibilityParams::kUpgradingFromLastContinuousToLatest || + currentFcv == FeatureCompatibilityParams::kUpgradingFromLastLTSToLatest) { + return FeatureCompatibilityParams::kLatest; + } else if (currentFcv == FeatureCompatibilityParams::kLastContinuous || + currentFcv == + FeatureCompatibilityParams::kDowngradingFromLatestToLastContinuous || + currentFcv == + FeatureCompatibilityParams::kUpgradingFromLastLTSToLastContinuous) { + // (Generic FCV reference): These FCV checks should exist across LTS binary + // versions. + return FeatureCompatibilityParams::kLastContinuous; + } else { // (Generic FCV reference): This FCV reference should exist across LTS binary // versions. - SetFeatureCompatibilityVersion setLastLTSCmd( - ServerGlobalParams::FeatureCompatibility::kLastLTS); - // The serialize function generated by IDL requires the DB name to be set. - setLastLTSCmd.setDbName(NamespaceString::kAdminDb); - setLastLTSCmd.serialize({}, &setFCVBuilder); - break; + invariant(currentFcv == + FeatureCompatibilityParams::kDowngradingFromLatestToLastLTS || + currentFcv == FeatureCompatibilityParams::kLastLTS); + return FeatureCompatibilityParams::kLastLTS; + } + }(); + + SetFeatureCompatibilityVersion setFcvCmd(setVersion); + setFcvCmd.setDbName(NamespaceString::kAdminDb); + // TODO (SERVER-50954): Remove this FCV check once 4.4 is no longer the last LTS + // version. + if (serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo( + FeatureCompatibilityParams::Version::kVersion47)) { + // fromConfigServer is a new parameter added to 4.8 with intention to be backported + // to 4.7. + setFcvCmd.setFromConfigServer(true); } - setFCVBuilder.append(WriteConcernOptions::kWriteConcernField, - opCtx->getWriteConcern().toBSON()); - auto versionResponse = _runCommandForAddShard( - opCtx, targeter.get(), NamespaceString::kAdminDb, setFCVBuilder.obj()); + + auto versionResponse = + _runCommandForAddShard(opCtx, + targeter.get(), + NamespaceString::kAdminDb, + setFcvCmd.toBSON(BSON(WriteConcernOptions::kWriteConcernField + << opCtx->getWriteConcern().toBSON()))); if (!versionResponse.isOK()) { return versionResponse.getStatus(); } |