summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Polato <paolo.polato@mongodb.com>2021-06-08 19:51:15 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-11 09:20:01 +0000
commite40a2e909716ecaa82a440e9b7831eae17140212 (patch)
tree2970cf1fbfc6849bf6b28a69d1d8241db4f0280c
parentdd6a29fcd092384c46676dace03e02674c2da911 (diff)
downloadmongo-e40a2e909716ecaa82a440e9b7831eae17140212.tar.gz
SERVER-52906 Applying metadata update before dispatching rollback task in moveChunk
-rw-r--r--jstests/libs/chunk_manipulation_util.js4
-rw-r--r--jstests/sharding/migration_waits_for_majority_commit.js6
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp48
3 files changed, 34 insertions, 24 deletions
diff --git a/jstests/libs/chunk_manipulation_util.js b/jstests/libs/chunk_manipulation_util.js
index 99a7e100b32..177e5af18ea 100644
--- a/jstests/libs/chunk_manipulation_util.js
+++ b/jstests/libs/chunk_manipulation_util.js
@@ -158,8 +158,8 @@ function waitForMoveChunkStep(shardConnection, stepNumber) {
}
var migrateStepNames = {
- deletedPriorDataInRange: 1,
- copiedIndexes: 2,
+ copiedIndexes: 1,
+ deletedPriorDataInRange: 2,
cloned: 3,
catchup: 4, // About to enter steady state.
steady: 5,
diff --git a/jstests/sharding/migration_waits_for_majority_commit.js b/jstests/sharding/migration_waits_for_majority_commit.js
index 8fbf88ffb39..6292bee5636 100644
--- a/jstests/sharding/migration_waits_for_majority_commit.js
+++ b/jstests/sharding/migration_waits_for_majority_commit.js
@@ -28,7 +28,7 @@ assert.commandWorked(st.s.adminCommand(
assert.eq(1, testDB.foo.find().readConcern("majority").itcount());
// Advance a migration to the beginning of the cloning phase.
-pauseMigrateAtStep(st.rs1.getPrimary(), 2);
+pauseMigrateAtStep(st.rs1.getPrimary(), migrateStepNames.deletedPriorDataInRange);
// For startParallelOps to write its state
let staticMongod = MongoRunner.runMongod({});
@@ -43,7 +43,7 @@ let awaitMigration = moveChunkParallel(staticMongod,
// Wait for the migration to reach the failpoint and allow any writes to become majority committed
// before pausing replication.
-waitForMigrateStep(st.rs1.getPrimary(), 2);
+waitForMigrateStep(st.rs1.getPrimary(), migrateStepNames.deletedPriorDataInRange);
st.rs1.awaitLastOpCommitted();
// Disable replication on the recipient shard's secondary node, so the recipient shard's majority
@@ -52,7 +52,7 @@ const destinationSec = st.rs1.getSecondary();
stopServerReplication(destinationSec);
// Allow the migration to begin cloning.
-unpauseMigrateAtStep(st.rs1.getPrimary(), 2);
+unpauseMigrateAtStep(st.rs1.getPrimary(), migrateStepNames.deletedPriorDataInRange);
// Check the migration coordinator document, because the moveChunk command itself
// will hang on trying to remove the recipient's range deletion entry with majority writeConcern
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 1eb833bb319..81bfbfdc255 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -965,6 +965,33 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
auto fromShard =
uassertStatusOK(Grid::get(outerOpCtx)->shardRegistry()->getShard(outerOpCtx, _fromShard));
+ // The conventional usage of retryable writes is to assign statement id's to all of
+ // the writes done as part of the data copying so that _recvChunkStart is
+ // conceptually a retryable write batch. However, we are using an alternate approach to do those
+ // writes under an AlternativeClientRegion because 1) threading the
+ // statement id's through to all the places where they are needed would make this code more
+ // complex, and 2) some of the operations, like creating the collection or building indexes, are
+ // not currently supported in retryable writes.
+ {
+ auto newClient = outerOpCtx->getServiceContext()->makeClient("MigrationCoordinator");
+ {
+ stdx::lock_guard<Client> lk(*newClient.get());
+ newClient->setSystemOperationKillableByStepdown(lk);
+ }
+
+ AlternativeClientRegion acr(newClient);
+ auto executor =
+ Grid::get(outerOpCtx->getServiceContext())->getExecutorPool()->getFixedExecutor();
+ auto altOpCtx = CancelableOperationContext(
+ cc().makeOperationContext(), outerOpCtx->getCancellationToken(), executor);
+
+ _dropLocalIndexesIfNecessary(altOpCtx.get(), _nss, donorCollectionOptionsAndIndexes);
+ cloneCollectionIndexesAndOptions(altOpCtx.get(), _nss, donorCollectionOptionsAndIndexes);
+
+ timing.done(1);
+ migrateThreadHangAtStep1.pauseWhileSet();
+ }
+
{
const ChunkRange range(_min, _max);
@@ -1023,38 +1050,21 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
outerOpCtx, latestOpTime, WriteConcerns::kMajorityWriteConcern, &ignoreResult));
});
- timing.done(1);
- migrateThreadHangAtStep1.pauseWhileSet();
+ timing.done(2);
+ migrateThreadHangAtStep2.pauseWhileSet();
}
- // The conventional usage of retryable writes is to assign statement id's to all of
- // the writes done as part of the data copying so that _recvChunkStart is
- // conceptually a retryable write batch. However, we are using an alternate approach to do those
- // writes under an AlternativeClientRegion because 1) threading the
- // statement id's through to all the places where they are needed would make this code more
- // complex, and 2) some of the operations, like creating the collection or building indexes, are
- // not currently supported in retryable writes.
auto newClient = outerOpCtx->getServiceContext()->makeClient("MigrationCoordinator");
{
stdx::lock_guard<Client> lk(*newClient.get());
newClient->setSystemOperationKillableByStepdown(lk);
}
-
AlternativeClientRegion acr(newClient);
auto executor =
Grid::get(outerOpCtx->getServiceContext())->getExecutorPool()->getFixedExecutor();
auto newOpCtxPtr = CancelableOperationContext(
cc().makeOperationContext(), outerOpCtx->getCancellationToken(), executor);
auto opCtx = newOpCtxPtr.get();
-
- {
- _dropLocalIndexesIfNecessary(opCtx, _nss, donorCollectionOptionsAndIndexes);
- cloneCollectionIndexesAndOptions(opCtx, _nss, donorCollectionOptionsAndIndexes);
-
- timing.done(2);
- migrateThreadHangAtStep2.pauseWhileSet();
- }
-
repl::OpTime lastOpApplied;
{
// 3. Initial bulk clone