From 346f9b67ee826fd655a56a5116f9c352f7a18397 Mon Sep 17 00:00:00 2001 From: Christopher Caplinger Date: Mon, 24 Jan 2022 15:14:10 +0000 Subject: SERVER-62882: Move Recipient Service opctx creation outside of lock (cherry picked from commit a94feb562cd9ffb42c10770fbf5b5d489875cc2f) --- src/mongo/db/repl/tenant_migration_recipient_service.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp index 24f5c1bda4d..b1c8e81b0d2 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp @@ -1644,14 +1644,13 @@ SemiFuture TenantMigrationRecipientService::Instance::_advanceStableTimestampToStartApplyingDonorOpTime() { Timestamp startApplyingDonorTimestamp; { + auto opCtx = cc().makeOperationContext(); stdx::lock_guard lk(_mutex); if (_stateDoc.getProtocol() != MigrationProtocolEnum::kShardMerge) { return SemiFuture::makeReady(); } - auto opCtx = cc().makeOperationContext(); - invariant(_stateDoc.getStartApplyingDonorOpTime()); startApplyingDonorTimestamp = _stateDoc.getStartApplyingDonorOpTime()->getTimestamp(); if (opCtx->getServiceContext()->getStorageEngine()->getStableTimestamp() >= @@ -2173,6 +2172,8 @@ SemiFuture TenantMigrationRecipientService::Instance::run( return AsyncTry([this, self = shared_from_this(), executor, token, cancelWhenDurable] { return ExecutorFuture(**executor) .then([this, self = shared_from_this()] { + auto opCtx = cc().makeOperationContext(); + stdx::unique_lock lk(_mutex); // Instance task can be started only once for the current term on a primary. invariant(!_taskState.isDone()); @@ -2197,7 +2198,6 @@ SemiFuture TenantMigrationRecipientService::Instance::run( // retry and we can delete immediately to allow the migration to restart. // Otherwise, there is a real conflict so we should throw // ConflictingInProgress. - auto opCtx = cc().makeOperationContext(); lk.unlock(); auto deleted = uassertStatusOK(tenantMigrationRecipientEntryHelpers:: @@ -2225,7 +2225,6 @@ SemiFuture TenantMigrationRecipientService::Instance::run( lk.unlock(); // Update the state document outside the mutex to avoid a deadlock in the // case of a concurrent stepdown. - auto opCtx = cc().makeOperationContext(); uassertStatusOK(tenantMigrationRecipientEntryHelpers::updateStateDoc( opCtx.get(), stateDoc)); return SemiFuture::makeReady(); -- cgit v1.2.1