diff options
author | Sophia Tan <sophia_tll@hotmail.com> | 2021-11-03 19:00:00 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-03 19:55:03 +0000 |
commit | 582e4151293d773c2de9fde20cc4726f79829ec0 (patch) | |
tree | b7f9fa666d3b791744ddc2888daa9baba3eccd68 | |
parent | fc94a79da8c730924d268082499b83677cba040b (diff) | |
download | mongo-582e4151293d773c2de9fde20cc4726f79829ec0.tar.gz |
SERVER-61114 Refactor getCanReadFuture for easier to understand
-rw-r--r-- | src/mongo/db/repl/tenant_migration_donor_access_blocker.cpp | 55 |
1 files 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<void> TenantMigrationDonorAccessBlocker::getCanReadFuture(Opera }(); stdx::lock_guard<Latch> 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<void>( - 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<void>(); - } - } - auto canRead = _state.isAllow() || _state.isAborted() || _state.isBlockWrites() || - *readTimestamp < *_blockTimestamp; + case BlockerState::State::kBlockWritesAndReads: + if (!readTimestamp || *readTimestamp < *_blockTimestamp) { + return SharedSemiFuture<void>(); + } else { + _stats.numBlockedReads.addAndFetch(1); + return _transitionOutOfBlockingPromise.getFuture(); + } - if (canRead) { - return SharedSemiFuture<void>(); - } + case BlockerState::State::kReject: + if (!readTimestamp) { + if (MONGO_unlikely(tenantMigrationDonorAllowsNonTimestampedReads.shouldFail()) || + commandDenyListAfterMigration.find(command) == + commandDenyListAfterMigration.end()) { + return SharedSemiFuture<void>(); + } + } else if (*readTimestamp < *_blockTimestamp) { + return SharedSemiFuture<void>(); + } - if (_state.isReject()) { - return SharedSemiFuture<void>( - Status(ErrorCodes::TenantMigrationCommitted, - "Read must be re-routed to the new owner of this tenant")); - } + return SharedSemiFuture<void>( + 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( |