summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJanna Golden <janna.golden@mongodb.com>2019-10-08 15:31:01 +0000
committerevergreen <evergreen@mongodb.com>2019-10-08 15:31:01 +0000
commit8ac53a6a615f14c78cf007ae6a58688849b63f56 (patch)
tree858df204e7172adbceacdd982d5abea760c01e13 /src
parent5710a3332449c1cbe2b4c46043f4283bd19a8a43 (diff)
downloadmongo-8ac53a6a615f14c78cf007ae6a58688849b63f56.tar.gz
SERVER-42783 Migrations should wait for majority replication of cloned docs when there are no xfer mods
(cherry picked from commit 2fb73bcd2515cd8d566fecc5b23ee9f6970b1716)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp21
-rw-r--r--src/mongo/db/s/migration_destination_manager.h2
2 files changed, 15 insertions, 8 deletions
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 8d5fd474f0c..bdf67e27f83 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -369,16 +369,22 @@ Status MigrationDestinationManager::start(const NamespaceString& nss,
return Status::OK();
}
-void MigrationDestinationManager::cloneDocumentsFromDonor(
+repl::OpTime MigrationDestinationManager::cloneDocumentsFromDonor(
OperationContext* opCtx,
stdx::function<void(OperationContext*, BSONObj)> insertBatchFn,
stdx::function<BSONObj(OperationContext*)> fetchBatchFn) {
ProducerConsumerQueue<BSONObj> batches(1);
+ repl::OpTime lastOpApplied;
+
stdx::thread inserterThread{[&] {
Client::initThreadIfNotAlready("chunkInserter");
auto inserterOpCtx = Client::getCurrent()->makeOperationContext();
- auto consumerGuard = MakeGuard([&] { batches.closeConsumerEnd(); });
+ auto consumerGuard = MakeGuard([&] {
+ batches.closeConsumerEnd();
+ lastOpApplied = repl::ReplClientInfo::forClient(inserterOpCtx->getClient()).getLastOp();
+ });
+
try {
while (true) {
auto nextBatch = batches.pop(inserterOpCtx.get());
@@ -414,6 +420,8 @@ void MigrationDestinationManager::cloneDocumentsFromDonor(
break;
}
}
+
+ return lastOpApplied;
}
Status MigrationDestinationManager::abort(const MigrationSessionId& sessionId) {
@@ -781,6 +789,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* opCtx,
MONGO_FAIL_POINT_PAUSE_WHILE_SET(migrateThreadHangAtStep2);
}
+ repl::OpTime lastOpApplied;
{
// 3. Initial bulk clone
setState(CLONE);
@@ -864,7 +873,9 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* opCtx,
return res;
};
- cloneDocumentsFromDonor(opCtx, insertBatchFn, fetchBatchFn);
+ // If running on a replicated system, we'll need to flush the docs we cloned to the
+ // secondaries
+ lastOpApplied = cloneDocumentsFromDonor(opCtx, insertBatchFn, fetchBatchFn);
timing.done(3);
MONGO_FAIL_POINT_PAUSE_WHILE_SET(migrateThreadHangAtStep3);
@@ -876,10 +887,6 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* opCtx,
}
}
- // If running on a replicated system, we'll need to flush the docs we cloned to the
- // secondaries
- repl::OpTime lastOpApplied = repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp();
-
const BSONObj xferModsRequest = createTransferModsRequest(_nss, *_sessionId);
{
diff --git a/src/mongo/db/s/migration_destination_manager.h b/src/mongo/db/s/migration_destination_manager.h
index 87627586076..efe35ffb0c3 100644
--- a/src/mongo/db/s/migration_destination_manager.h
+++ b/src/mongo/db/s/migration_destination_manager.h
@@ -109,7 +109,7 @@ public:
/**
* Clones documents from a donor shard.
*/
- static void cloneDocumentsFromDonor(
+ static repl::OpTime cloneDocumentsFromDonor(
OperationContext* opCtx,
stdx::function<void(OperationContext*, BSONObj)> insertBatchFn,
stdx::function<BSONObj(OperationContext*)> fetchBatchFn);