diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2022-03-17 07:22:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-17 07:49:56 +0000 |
commit | 27eb423d6ea3dc3d9be216ea452995ae2e159842 (patch) | |
tree | b10fc214c2df7d9e33fe8cd6d44acc1da4e82151 | |
parent | 853ae19875607294030344ec9155ae8cd8b1bf00 (diff) | |
download | mongo-27eb423d6ea3dc3d9be216ea452995ae2e159842.tar.gz |
SERVER-64558 Check for critical section before reading the DB/Collection version
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime.cpp | 22 | ||||
-rw-r--r-- | src/mongo/db/s/database_sharding_state.cpp | 10 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index fa4e68cc9af..0cfb71834f6 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -344,17 +344,6 @@ CollectionShardingRuntime::_getMetadataWithVersionCheckAt( auto csrLock = CSRLock::lockShared(opCtx, this); - auto optCurrentMetadata = _getCurrentMetadataIfKnown(atClusterTime); - uassert(StaleConfigInfo(_nss, - receivedShardVersion, - boost::none /* wantedVersion */, - ShardingState::get(opCtx)->shardId()), - str::stream() << "sharding status of collection " << _nss.ns() - << " is not currently known and needs to be recovered", - optCurrentMetadata); - - const auto& currentMetadata = optCurrentMetadata->get(); - { auto criticalSectionSignal = _critSec.getSignal( opCtx->lockState()->isWriteLocked() ? ShardingMigrationCriticalSection::kWrite @@ -368,6 +357,17 @@ CollectionShardingRuntime::_getMetadataWithVersionCheckAt( !criticalSectionSignal); } + auto optCurrentMetadata = _getCurrentMetadataIfKnown(atClusterTime); + uassert(StaleConfigInfo(_nss, + receivedShardVersion, + boost::none /* wantedVersion */, + ShardingState::get(opCtx)->shardId()), + str::stream() << "sharding status of collection " << _nss.ns() + << " is not currently known and needs to be recovered", + optCurrentMetadata); + + const auto& currentMetadata = optCurrentMetadata->get(); + auto wantedShardVersion = currentMetadata.getShardVersion(); if (wantedShardVersion.isWriteCompatibleWith(receivedShardVersion) || diff --git a/src/mongo/db/s/database_sharding_state.cpp b/src/mongo/db/s/database_sharding_state.cpp index 40b1fcebf25..a4c0dff2667 100644 --- a/src/mongo/db/s/database_sharding_state.cpp +++ b/src/mongo/db/s/database_sharding_state.cpp @@ -179,11 +179,6 @@ void DatabaseShardingState::checkDbVersion(OperationContext* opCtx, DSSLock&) co if (!clientDbVersion) return; - uassert(StaleDbRoutingVersion(_dbName, *clientDbVersion, boost::none), - str::stream() << "sharding status of database " << _dbName - << " is not currently known and needs to be recovered", - _optDatabaseInfo); - { auto criticalSectionSignal = _critSec.getSignal( opCtx->lockState()->isWriteLocked() ? ShardingMigrationCriticalSection::kWrite @@ -194,6 +189,11 @@ void DatabaseShardingState::checkDbVersion(OperationContext* opCtx, DSSLock&) co !criticalSectionSignal); } + uassert(StaleDbRoutingVersion(_dbName, *clientDbVersion, boost::none), + str::stream() << "sharding status of database " << _dbName + << " is not currently known and needs to be recovered", + _optDatabaseInfo); + const auto& dbVersion = _optDatabaseInfo->getVersion(); uassert(StaleDbRoutingVersion(_dbName, *clientDbVersion, dbVersion), str::stream() << "dbVersion mismatch for database " << _dbName, |