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-04 17:26:03 +0000 |
commit | 9b27d9c7582ca544b0c27b119107b57b4e2b8d50 (patch) | |
tree | 7607b02719e070a629963120c467b62885796074 | |
parent | e964c8ee8013a5341159da81837635d54cd3f3e9 (diff) | |
download | mongo-9b27d9c7582ca544b0c27b119107b57b4e2b8d50.tar.gz |
SERVER-61027 Add permitMigration flag to prevent balancer rounds and migrations commit
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 0f2349e84a6..f139d1d8f14 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 @@ -351,7 +351,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 870a6bc6392..740da8d9e59 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 @@ -908,7 +908,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 05b0e5ed610..f7d5641ec80 100644 --- a/src/mongo/s/catalog/type_collection.h +++ b/src/mongo/s/catalog/type_collection.h @@ -168,6 +168,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 d9e77d48b4e..118f08ec15c 100644 --- a/src/mongo/s/catalog/type_collection.idl +++ b/src/mongo/s/catalog/type_collection.idl @@ -166,3 +166,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 |