From 49ed92262fe85f3e2be497c12159f8821d02db62 Mon Sep 17 00:00:00 2001 From: Jordi Serra Torrens Date: Thu, 13 Jan 2022 16:48:04 +0000 Subject: [PATCH] Repro SERVER-61755 --- .../sharding/move_chunk_refine_shardkey.js | 47 +++++++++++++++++++ src/mongo/db/s/migration_util.cpp | 3 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 jstests/sharding/move_chunk_refine_shardkey.js diff --git a/jstests/sharding/move_chunk_refine_shardkey.js b/jstests/sharding/move_chunk_refine_shardkey.js new file mode 100644 index 00000000000..843b3073e1b --- /dev/null +++ b/jstests/sharding/move_chunk_refine_shardkey.js @@ -0,0 +1,47 @@ +(function() { +'use strict'; + +load('jstests/libs/fail_point_util.js'); +load('jstests/libs/parallel_shell_helpers.js'); +load("jstests/sharding/libs/find_chunks_util.js"); + +const st = new ShardingTest({shards: 2, rs: {nodes: 3}}); +const dbName = 'myDB'; +const collName = 'coll'; + +assert.commandWorked(st.s.getDB(dbName).dropDatabase()); +assert.commandWorked( + st.s.adminCommand({enableSharding: dbName, primaryShard: st.shard0.shardName})); + +const coll = st.s.getDB(dbName).getCollection(collName); + +assert.commandWorked(coll.insert({sk: -1})); +assert.commandWorked(coll.insert({sk: 1})); + +assert.commandWorked(coll.createIndex({sk: 1, plus: 1})); + +st.shardColl(coll.getName(), {sk: 1}, {sk: 0}, false, dbName); + +const decisionFp = configureFailPoint(st.rs0.getPrimary(), "hangBeforeMakingCommitDecisionDurable"); +const awaitMigration = + startParallelShell(funWithArgs(function(ns, toShardName) { + db.adminCommand({moveChunk: ns, find: {sk: -1}, to: toShardName}); + }, coll.getFullName(), st.shard1.shardName), st.s.port); + +decisionFp.wait(); +let newPrimary = st.rs0.getSecondary() +let migrationRecoveryFp = configureFailPoint(newPrimary, "hangBeforeMigrationRecovery"); +st.rs0.stepUp(newPrimary) +// Unblock old primary +decisionFp.off(); +awaitMigration(); +// Wait new primary to hang in recovery +migrationRecoveryFp.wait(); + +assert.commandWorked( + st.s.adminCommand({refineCollectionShardKey: coll.getFullName(), key: {sk: 1, plus: 1}})) + +migrationRecoveryFp.off(); + +st.stop(); +})(); diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp index 0fad3c1de46..5f98fdba7f7 100644 --- a/src/mongo/db/s/migration_util.cpp +++ b/src/mongo/db/s/migration_util.cpp @@ -100,6 +100,7 @@ MONGO_FAIL_POINT_DEFINE(hangInReadyRangeDeletionLocallyInterruptible); MONGO_FAIL_POINT_DEFINE(hangInReadyRangeDeletionLocallyThenSimulateErrorUninterruptible); MONGO_FAIL_POINT_DEFINE(hangInAdvanceTxnNumInterruptible); MONGO_FAIL_POINT_DEFINE(hangInAdvanceTxnNumThenSimulateErrorUninterruptible); +MONGO_FAIL_POINT_DEFINE(hangBeforeMigrationRecovery); const char kSourceShard[] = "source"; const char kDestinationShard[] = "destination"; @@ -982,7 +983,7 @@ void recoverMigrationCoordinations(OperationContext* opCtx, doc.getPreMigrationChunkVersion()); hangInRefreshFilteringMetadataUntilSuccessInterruptible.pauseWhileSet(opCtx); - + hangBeforeMigrationRecovery.pauseWhileSet(opCtx); auto currentMetadata = forceGetCurrentMetadata(opCtx, doc.getNss()); if (hangInRefreshFilteringMetadataUntilSuccessThenSimulateErrorUninterruptible -- 2.17.1