diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2022-01-12 17:52:29 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-12 18:22:40 +0000 |
commit | c7b4557516fee750c4e743d5d67b3281bdcccfb1 (patch) | |
tree | f94b66a30990f063fcd03b2802ecc9434f8ac620 | |
parent | eb75b6ccc62f7c8ea26a57c1b5eb96a41809396a (diff) | |
download | mongo-c7b4557516fee750c4e743d5d67b3281bdcccfb1.tar.gz |
SERVER-59689 Prevent setting FCV < 5.3 in case of ongoing defragmentation
3 files changed, 49 insertions, 0 deletions
diff --git a/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js b/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js index 390d53a664c..ccb27566ac0 100644 --- a/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js +++ b/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js @@ -172,6 +172,25 @@ function checkClusterAfterBinaryDowngrade(fcv, call1Ns, call2Ns, call3Ns) { testDisabledLongNameSupport(call3Ns); } +// TODO SERVER-xyz review this check before v6.0 branches out +function checkDowngradeDisallowedDuringDefragmentation(oldVersion) { + // Block defragmenter to be sure the `balancerShouldMergeChunks` field is not unset too early + st.forEachConfigServer((config) => { + assert.commandWorked(config.adminCommand( + {configureFailPoint: "beforeTransitioningDefragmentationPhase", mode: "alwaysOn"})); + }); + + // Pretend one collection is being defragmented to test that downgrade is not allowed + assert.commandWorked( + st.config.collections.updateOne({}, {$set: {balancerShouldMergeChunks: true}})); + var setFCVCmdResult = st.s.adminCommand({setFeatureCompatibilityVersion: oldVersion}); + assert.commandFailedWithCode(setFCVCmdResult, ErrorCodes.CannotDowngrade); + + // Rollback the change to allow downgrade + assert.commandWorked(st.config.collections.updateOne( + {balancerShouldMergeChunks: {$exists: true}}, {$unset: {balancerShouldMergeChunks: 1}})); +} + for (const oldVersion of [lastLTSFCV, lastContinuousFCV]) { ////////////////////////////// // Setting and testing cluster using old binaries in default FCV mode @@ -201,6 +220,7 @@ for (const oldVersion of [lastLTSFCV, lastContinuousFCV]) { // Setting and testing cluster using old binaries in old FCV mode jsTest.log('Downgrading FCV to ' + oldVersion); + checkDowngradeDisallowedDuringDefragmentation(oldVersion); assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: oldVersion})); checkClusterAfterFCVDowngrade(); diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index b137279d485..d7d6d9f6d8e 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -530,6 +530,26 @@ private: requestedVersion); if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { + { + // TODO SERVER-xyz review/adapt this scope before v6.0 branches out + // Make sure no collection is currently being defragmented + DBDirectClient client(opCtx); + + const BSONObj collBeingDefragmentedQuery = BSON( + CollectionType::kBalancerShouldMergeChunksFieldName << BSON("$exists" << true)); + + const bool isDefragmenting = client.count(CollectionType::ConfigNS, + collBeingDefragmentedQuery, + 0 /*options*/, + 1 /* limit */); + + uassert(ErrorCodes::CannotDowngrade, + str::stream() << "Cannot downgrade the cluster when there are collections " + "being defragmented. Please drain all the defragmentation " + "processes before downgrading.", + !isDefragmenting); + } + // Tell the shards to enter phase-1 of setFCV auto requestPhase1 = request; requestPhase1.setFromConfigServer(true); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp index 4b0178fb8d6..2851b944304 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp @@ -48,6 +48,7 @@ #include "mongo/db/catalog/collection_options.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/db/commands/feature_compatibility_version.h" #include "mongo/db/internal_transactions_feature_flag_gen.h" #include "mongo/db/logical_session_cache.h" #include "mongo/db/namespace_string.h" @@ -555,6 +556,14 @@ void ShardingCatalogManager::configureCollectionAutoSplit( boost::optional<bool> balancerShouldMergeChunks, boost::optional<bool> enableAutoSplitter) { + // Hold the FCV region to serialize with the setFeatureCompatibilityVersion command + FixedFCVRegion fcvRegion(opCtx); + uassert(ErrorCodes::IllegalOperation, + "_configsvrConfigureAutoSplit can only be run when the cluster is in feature " + "compatibility versions greater or equal than 5.3.", + serverGlobalParams.featureCompatibility.isGreaterThanOrEqualTo( + multiversion::FeatureCompatibilityVersion::kVersion_5_3)); + uassert(ErrorCodes::InvalidOptions, "invalid collection auto splitter config update", maxChunkSizeBytes || balancerShouldMergeChunks || enableAutoSplitter); |