diff options
author | Marcos José Grillo Ramirez <marcos.grillo@mongodb.com> | 2021-11-04 16:45:02 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-12 17:09:51 +0000 |
commit | a68550916c183deb6703879692ed070c0c56a0b8 (patch) | |
tree | 3680e54f94ccde682f1276414248d6fd5fa2590d | |
parent | 3df2c98107f71668cf8058a1f6cabfc0576c835e (diff) | |
download | mongo-a68550916c183deb6703879692ed070c0c56a0b8.tar.gz |
SERVER-61027 Add permitMigration flag to prevent balancer rounds and migrations commit
(cherry picked from commit 9b27d9c7582ca544b0c27b119107b57b4e2b8d50)
5 files changed, 49 insertions, 2 deletions
diff --git a/jstests/sharding/move_chunk_allowMigrations.js b/jstests/sharding/move_chunk_allowMigrations.js index 1ef488f7f33..4db3d97b946 100644 --- a/jstests/sharding/move_chunk_allowMigrations.js +++ b/jstests/sharding/move_chunk_allowMigrations.js @@ -62,6 +62,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. // @@ -206,6 +238,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 404ca70e17b..c25d4212ac7 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 @@ -365,7 +365,7 @@ StatusWith<MigrateInfoVector> BalancerChunkSelectionPolicyImpl::selectChunksToMo for (const auto& coll : collections) { 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 0fb31b20283..cf6cfd5f1e6 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 @@ -907,7 +907,7 @@ StatusWith<BSONObj> 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 = BSON(ChunkType::collectionUUID() << coll.getUuid()); diff --git a/src/mongo/s/catalog/type_collection.h b/src/mongo/s/catalog/type_collection.h index fb032a94f72..9a478c01248 100644 --- a/src/mongo/s/catalog/type_collection.h +++ b/src/mongo/s/catalog/type_collection.h @@ -163,6 +163,11 @@ public: setPre50CompatibleAllowMigrations(false); } + // TODO SERVER-61033: remove after permitMigrations have been merge with allowMigrations. + bool getPermitMigrations() const { + return CollectionTypeBase::getPermitMigrations().get_value_or(true); + } + SupportingLongNameStatusEnum getSupportingLongName() const; void setSupportingLongName(SupportingLongNameStatusEnum value); diff --git a/src/mongo/s/catalog/type_collection.idl b/src/mongo/s/catalog/type_collection.idl index acff4f93d88..c6f36282f6b 100644 --- a/src/mongo/s/catalog/type_collection.idl +++ b/src/mongo/s/catalog/type_collection.idl @@ -162,3 +162,10 @@ structs: sharded collection UUID, instead of the namespace, as part of their names, i.e., system.cache.chunks.<UUID>." 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
\ No newline at end of file |