From e8ae5a22de1ecd62d6a59908bb351022dc531519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Jos=C3=A9=20Grillo=20Ramirez?= Date: Thu, 4 Nov 2021 16:45:02 +0000 Subject: SERVER-61027 Add permitMigration flag to prevent balancer rounds and migrations commit (cherry picked from commit 9b27d9c7582ca544b0c27b119107b57b4e2b8d50) --- jstests/sharding/move_chunk_allowMigrations.js | 35 ++++++++++++++++++++++ .../balancer_chunk_selection_policy_impl.cpp | 2 +- .../sharding_catalog_manager_chunk_operations.cpp | 2 +- src/mongo/s/catalog/type_collection.h | 5 ++++ src/mongo/s/catalog/type_collection.idl | 7 +++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/jstests/sharding/move_chunk_allowMigrations.js b/jstests/sharding/move_chunk_allowMigrations.js index c9c1d9d0b6e..a8215c9604e 100644 --- a/jstests/sharding/move_chunk_allowMigrations.js +++ b/jstests/sharding/move_chunk_allowMigrations.js @@ -63,6 +63,38 @@ const setUpDb = function setUpDatabaseAndEnableSharding() { assert.eq(false, cachedEntry.allowMigrations); })(); +// TODO SERVER-61033: remove after permitMigrations have been merged with allowMigrations. +// Tests that moveChunk does not succeed when {permitMigrations: false} +(function testPermitMigrationsFalsePreventsMoveChunk() { + setUpDb(); + + const collName = "collA"; + const ns = dbName + "." + collName; + + assert.commandWorked(st.s.getDB(dbName).getCollection(collName).insert({_id: 0})); + assert.commandWorked(st.s.getDB(dbName).getCollection(collName).insert({_id: 1})); + assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: 1}})); + + // Confirm that an inProgress moveChunk fails once {allowMigrations: false} + const fp = configureFailPoint(st.shard0, "moveChunkHangAtStep4"); + const awaitResult = startParallelShell( + funWithArgs(function(ns, toShardName) { + assert.commandFailedWithCode( + db.adminCommand({moveChunk: ns, find: {_id: 0}, to: toShardName}), + ErrorCodes.ConflictingOperationInProgress); + }, ns, st.shard1.shardName), st.s.port); + fp.wait(); + assert.commandWorked(configDB.collections.updateOne( + {_id: ns}, {$set: {permitMigrations: false}}, {writeConcern: {w: "majority"}})); + fp.off(); + awaitResult(); + + // {permitMigrations: false} is set, sending a new moveChunk command should also fail. + assert.commandFailedWithCode( + st.s.adminCommand({moveChunk: ns, find: {_id: 0}, to: st.shard1.shardName}), + ErrorCodes.ConflictingOperationInProgress); +})(); + // Tests {allowMigrations: false} disables balancing for collB and does not interfere with balancing // for collA. // @@ -203,6 +235,9 @@ testBalancer(false /* allowMigrations */, {}); testBalancer(false /* allowMigrations */, {noBalance: false}); testBalancer(false /* allowMigrations */, {noBalance: true}); +// TODO SERVER-61033: merge permitMigrations with allowMigrations. +testBalancer(true /* allowMigrations */, {permitMigrations: false}); + // Test the _configsvrSetAllowMigrations internal command testConfigsvrSetAllowMigrationsCommand(); diff --git a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp index 6d956beba3f..243e2b1b938 100644 --- a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp +++ b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp @@ -373,7 +373,7 @@ StatusWith BalancerChunkSelectionPolicyImpl::selectChunksToMo const NamespaceString& nss(coll.getNss()); - if (!coll.getAllowBalance() || !coll.getAllowMigrations()) { + if (!coll.getAllowBalance() || !coll.getAllowMigrations() || !coll.getPermitMigrations()) { LOGV2_DEBUG(21851, 1, "Not balancing collection {namespace}; explicitly disabled.", diff --git a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp index 67bca49c9d1..d3d63098cae 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp @@ -1096,7 +1096,7 @@ StatusWith ShardingCatalogManager::commitChunkMigration( const CollectionType coll(findCollResponse.docs[0]); uassert(ErrorCodes::ConflictingOperationInProgress, "Collection is undergoing changes and chunks cannot be moved", - coll.getAllowMigrations()); + coll.getAllowMigrations() && coll.getPermitMigrations()); const auto findChunkQuery = coll.getTimestamp() ? BSON(ChunkType::collectionUUID() << coll.getUuid()) diff --git a/src/mongo/s/catalog/type_collection.h b/src/mongo/s/catalog/type_collection.h index a5710d08f76..e44f7ee5727 100644 --- a/src/mongo/s/catalog/type_collection.h +++ b/src/mongo/s/catalog/type_collection.h @@ -161,6 +161,11 @@ public: else setPre50CompatibleAllowMigrations(false); } + + // TODO SERVER-61033: remove after permitMigrations have been merge with allowMigrations. + bool getPermitMigrations() const { + return CollectionTypeBase::getPermitMigrations().get_value_or(true); + } }; } // namespace mongo diff --git a/src/mongo/s/catalog/type_collection.idl b/src/mongo/s/catalog/type_collection.idl index 5917c2faad5..252c8e26538 100644 --- a/src/mongo/s/catalog/type_collection.idl +++ b/src/mongo/s/catalog/type_collection.idl @@ -145,3 +145,10 @@ structs: description: "Time-series collection fields. Only set when this is a time-series buckets collection." optional: true +# TODO SERVER-61033: merge this flag with allowMigrations. + permitMigrations: + type: bool + description: "DEPRECATED flag that determines wether this collection allows chunks to + move. This will only prevent migration from committing and new balancer + rounds, this flag will not be loaded by shards." + optional: true -- cgit v1.2.1