From 582e4151293d773c2de9fde20cc4726f79829ec0 Mon Sep 17 00:00:00 2001 From: Sophia Tan Date: Wed, 3 Nov 2021 19:00:00 +0000 Subject: SERVER-61114 Refactor getCanReadFuture for easier to understand --- .../repl/tenant_migration_donor_access_blocker.cpp | 55 +++++++++++----------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/mongo/db/repl/tenant_migration_donor_access_blocker.cpp b/src/mongo/db/repl/tenant_migration_donor_access_blocker.cpp index 6cff13ad468..994cebcaadd 100644 --- a/src/mongo/db/repl/tenant_migration_donor_access_blocker.cpp +++ b/src/mongo/db/repl/tenant_migration_donor_access_blocker.cpp @@ -153,38 +153,39 @@ SharedSemiFuture TenantMigrationDonorAccessBlocker::getCanReadFuture(Opera }(); stdx::lock_guard lk(_mutex); - if (!readTimestamp) { - if (!MONGO_unlikely(tenantMigrationDonorAllowsNonTimestampedReads.shouldFail()) && - _state.isReject() && - commandDenyListAfterMigration.find(command) != commandDenyListAfterMigration.end()) { - LOGV2_DEBUG(5505100, - 1, - "Donor blocking non-timestamped reads after committed migration", - "command"_attr = command, - "tenantId"_attr = _tenantId); - return SharedSemiFuture( - Status(ErrorCodes::TenantMigrationCommitted, - "Read must be re-routed to the new owner of this tenant")); - } else { + + switch (_state.getState()) { + case BlockerState::State::kAllow: + case BlockerState::State::kBlockWrites: + case BlockerState::State::kAborted: return SharedSemiFuture(); - } - } - auto canRead = _state.isAllow() || _state.isAborted() || _state.isBlockWrites() || - *readTimestamp < *_blockTimestamp; + case BlockerState::State::kBlockWritesAndReads: + if (!readTimestamp || *readTimestamp < *_blockTimestamp) { + return SharedSemiFuture(); + } else { + _stats.numBlockedReads.addAndFetch(1); + return _transitionOutOfBlockingPromise.getFuture(); + } - if (canRead) { - return SharedSemiFuture(); - } + case BlockerState::State::kReject: + if (!readTimestamp) { + if (MONGO_unlikely(tenantMigrationDonorAllowsNonTimestampedReads.shouldFail()) || + commandDenyListAfterMigration.find(command) == + commandDenyListAfterMigration.end()) { + return SharedSemiFuture(); + } + } else if (*readTimestamp < *_blockTimestamp) { + return SharedSemiFuture(); + } - if (_state.isReject()) { - return SharedSemiFuture( - Status(ErrorCodes::TenantMigrationCommitted, - "Read must be re-routed to the new owner of this tenant")); - } + return SharedSemiFuture( + Status(ErrorCodes::TenantMigrationCommitted, + "Read must be re-routed to the new owner of this tenant")); - _stats.numBlockedReads.addAndFetch(1); - return _transitionOutOfBlockingPromise.getFuture(); + default: + MONGO_UNREACHABLE; + } } Status TenantMigrationDonorAccessBlocker::checkIfLinearizableReadWasAllowed( -- cgit v1.2.1