From fbdfaa2530248b18b4327527f08d83eb283f67a2 Mon Sep 17 00:00:00 2001 From: Cheahuychou Mao Date: Fri, 11 Jun 2021 18:11:43 +0000 Subject: SERVER-55573 Deadlock between stepdown and chunk migration --- src/mongo/db/s/migration_destination_manager.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp index c55e1e6fec9..4478a436733 100644 --- a/src/mongo/db/s/migration_destination_manager.cpp +++ b/src/mongo/db/s/migration_destination_manager.cpp @@ -480,9 +480,19 @@ repl::OpTime MigrationDestinationManager::cloneDocumentsFromDonor( repl::OpTime lastOpApplied; stdx::thread inserterThread{[&] { - Client::initKillableThread("chunkInserter", opCtx->getServiceContext()); + Client::initThread("chunkInserter", opCtx->getServiceContext(), nullptr); + auto newClient = Client::getCurrent(); + { + stdx::lock_guard lk(*newClient); + newClient->setSystemOperationKillable(lk); + } + auto inserterOpCtx = cc().makeOperationContext(); + inserterOpCtx->setAlwaysInterruptAtStepDownOrUp(); + { + stdx::lock_guard lk(*opCtx->getClient()); + opCtx->checkForInterrupt(); + } - auto inserterOpCtx = Client::getCurrent()->makeOperationContext(); auto consumerGuard = makeGuard([&] { batches.closeConsumerEnd(); lastOpApplied = repl::ReplClientInfo::forClient(inserterOpCtx->getClient()).getLastOp(); @@ -1051,6 +1061,11 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) { AlternativeClientRegion acr(newClient); auto newOpCtxPtr = cc().makeOperationContext(); + newOpCtxPtr->setAlwaysInterruptAtStepDownOrUp(); + { + stdx::lock_guard lk(*outerOpCtx->getClient()); + outerOpCtx->checkForInterrupt(); + } auto opCtx = newOpCtxPtr.get(); { -- cgit v1.2.1