diff options
-rw-r--r-- | src/mongo/db/repl/tenant_migration_recipient_service.cpp | 7 |
1 files 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<void> TenantMigrationRecipientService::Instance::_advanceStableTimestampToStartApplyingDonorOpTime() { Timestamp startApplyingDonorTimestamp; { + auto opCtx = cc().makeOperationContext(); stdx::lock_guard lk(_mutex); if (_stateDoc.getProtocol() != MigrationProtocolEnum::kShardMerge) { return SemiFuture<void>::makeReady(); } - auto opCtx = cc().makeOperationContext(); - invariant(_stateDoc.getStartApplyingDonorOpTime()); startApplyingDonorTimestamp = _stateDoc.getStartApplyingDonorOpTime()->getTimestamp(); if (opCtx->getServiceContext()->getStorageEngine()->getStableTimestamp() >= @@ -2173,6 +2172,8 @@ SemiFuture<void> 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<void> 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<void> 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<void>::makeReady(); |