diff options
author | Randolph Tan <randolph@10gen.com> | 2019-06-18 14:29:46 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2019-06-27 14:08:59 -0400 |
commit | 0d07bf5e7a72a5bce3f7d7d681a71d7ecfe7eb8c (patch) | |
tree | 6316b1ceee6a890fe075873bb8af853ba37dc750 /src/mongo/db/s/collection_sharding_state.cpp | |
parent | d6834482ef9bbca8fd81e82483dedde965de9574 (diff) | |
download | mongo-0d07bf5e7a72a5bce3f7d7d681a71d7ecfe7eb8c.tar.gz |
SERVER-40258 Relax locking requirements for sharding metadata refresh on shards
Diffstat (limited to 'src/mongo/db/s/collection_sharding_state.cpp')
-rw-r--r-- | src/mongo/db/s/collection_sharding_state.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/mongo/db/s/collection_sharding_state.cpp b/src/mongo/db/s/collection_sharding_state.cpp index e0dd987600d..feb519090e3 100644 --- a/src/mongo/db/s/collection_sharding_state.cpp +++ b/src/mongo/db/s/collection_sharding_state.cpp @@ -160,12 +160,8 @@ void CollectionShardingState::report(OperationContext* opCtx, BSONObjBuilder* bu } ScopedCollectionMetadata CollectionShardingState::getOrphansFilter(OperationContext* opCtx) { - const auto receivedShardVersion = getOperationReceivedVersion(opCtx, _nss); - if (!receivedShardVersion) - return {kUnshardedCollection}; - const auto atClusterTime = repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime(); - auto optMetadata = _getMetadata(atClusterTime); + auto optMetadata = _getMetadataWithVersionCheckAt(opCtx, atClusterTime); if (!optMetadata) return {kUnshardedCollection}; @@ -199,26 +195,34 @@ boost::optional<ChunkVersion> CollectionShardingState::getCurrentShardVersionIfK } void CollectionShardingState::checkShardVersionOrThrow(OperationContext* opCtx) { + (void)_getMetadataWithVersionCheckAt(opCtx, boost::none); +} + +boost::optional<ScopedCollectionMetadata> CollectionShardingState::_getMetadataWithVersionCheckAt( + OperationContext* opCtx, const boost::optional<mongo::LogicalTime>& atClusterTime) { const auto optReceivedShardVersion = getOperationReceivedVersion(opCtx, _nss); if (!optReceivedShardVersion) - return; + return ScopedCollectionMetadata(kUnshardedCollection); const auto& receivedShardVersion = *optReceivedShardVersion; if (ChunkVersion::isIgnoredVersion(receivedShardVersion)) { - return; + return boost::none; } // An operation with read concern 'available' should never have shardVersion set. invariant(repl::ReadConcernArgs::get(opCtx).getLevel() != repl::ReadConcernLevel::kAvailableReadConcern); - const auto metadata = getCurrentMetadata(); - const auto wantedShardVersion = - metadata->isSharded() ? metadata->getShardVersion() : ChunkVersion::UNSHARDED(); + auto csrLock = CSRLock::lockShared(opCtx, this); + + auto metadata = _getMetadata(atClusterTime); + auto wantedShardVersion = ChunkVersion::UNSHARDED(); + if (metadata && (*metadata)->isSharded()) { + wantedShardVersion = (*metadata)->getShardVersion(); + } auto criticalSectionSignal = [&] { - auto csrLock = CSRLock::lockShared(opCtx, this); return _critSec.getSignal(opCtx->lockState()->isWriteLocked() ? ShardingMigrationCriticalSection::kWrite : ShardingMigrationCriticalSection::kRead); @@ -235,7 +239,7 @@ void CollectionShardingState::checkShardVersionOrThrow(OperationContext* opCtx) } if (receivedShardVersion.isWriteCompatibleWith(wantedShardVersion)) { - return; + return metadata; } // |