diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2020-05-26 03:40:11 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-26 10:05:06 +0000 |
commit | 764b77bfe24784e740527b167c0a21d22842af30 (patch) | |
tree | 6389d3f37dfa0ddaa97553cce52949452d1c7fd5 /src | |
parent | 5648a670c3392bae32963fd2af3488d6f9c96ca7 (diff) | |
download | mongo-764b77bfe24784e740527b167c0a21d22842af30.tar.gz |
SERVER-48401 Ensure the CSR lock has the correct namespace
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime.cpp | 20 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime.h | 21 |
2 files changed, 18 insertions, 23 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index 54b7cce9178..56b9c141c76 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -89,17 +89,15 @@ boost::optional<ChunkVersion> getOperationReceivedVersion(OperationContext* opCt } // namespace CollectionShardingRuntime::CollectionShardingRuntime( - ServiceContext* sc, + ServiceContext* service, NamespaceString nss, std::shared_ptr<executor::TaskExecutor> rangeDeleterExecutor) - : _nss(std::move(nss)), - _rangeDeleterExecutor(rangeDeleterExecutor), - _stateChangeMutex(nss.toString()), - _serviceContext(sc) { - if (isNamespaceAlwaysUnsharded(_nss)) { - _metadataType = MetadataType::kUnsharded; - } -} + : _serviceContext(service), + _nss(std::move(nss)), + _rangeDeleterExecutor(std::move(rangeDeleterExecutor)), + _stateChangeMutex(_nss.toString()), + _metadataType(isNamespaceAlwaysUnsharded(_nss) ? MetadataType::kUnsharded + : MetadataType::kUnknown) {} CollectionShardingRuntime* CollectionShardingRuntime::get(OperationContext* opCtx, const NamespaceString& nss) { @@ -421,8 +419,8 @@ size_t CollectionShardingRuntime::numberOfRangesScheduledForDeletion() const { return 0; } -CollectionCriticalSection::CollectionCriticalSection(OperationContext* opCtx, NamespaceString ns) - : _nss(std::move(ns)), _opCtx(opCtx) { +CollectionCriticalSection::CollectionCriticalSection(OperationContext* opCtx, NamespaceString nss) + : _opCtx(opCtx), _nss(std::move(nss)) { AutoGetCollection autoColl(_opCtx, _nss, MODE_X, diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h index 6908536c817..31d901dbae2 100644 --- a/src/mongo/db/s/collection_sharding_runtime.h +++ b/src/mongo/db/s/collection_sharding_runtime.h @@ -50,7 +50,7 @@ extern AtomicWord<int> migrationLockAcquisitionMaxWaitMS; class CollectionShardingRuntime final : public CollectionShardingState, public Decorable<CollectionShardingRuntime> { public: - CollectionShardingRuntime(ServiceContext* sc, + CollectionShardingRuntime(ServiceContext* service, NamespaceString nss, std::shared_ptr<executor::TaskExecutor> rangeDeleterExecutor); @@ -221,6 +221,9 @@ private: std::shared_ptr<ScopedCollectionDescription::Impl> _getMetadataWithVersionCheckAt( OperationContext* opCtx, const boost::optional<mongo::LogicalTime>& atClusterTime); + // The service context under which this instance runs + ServiceContext* const _serviceContext; + // Namespace this state belongs to. const NamespaceString _nss; @@ -236,15 +239,12 @@ private: // Must hold CSRLock while accessing. ShardingMigrationCriticalSection _critSec; + // Protects state around the metadata manager below mutable Mutex _metadataManagerLock = MONGO_MAKE_LATCH("CollectionShardingRuntime::_metadataManagerLock"); // Tracks whether the filtering metadata is unknown, unsharded, or sharded - enum class MetadataType { - kUnknown, - kUnsharded, - kSharded - } _metadataType{MetadataType::kUnknown}; + enum class MetadataType { kUnknown, kUnsharded, kSharded } _metadataType; // If the collection is sharded, contains all the metadata associated with this collection. // @@ -254,9 +254,6 @@ private: // Used for testing to check the number of times a new MetadataManager has been installed. std::uint64_t _numMetadataManagerChanges{0}; - - // Used to get the shardId if no metadata is known when calling getCollectionDescription - ServiceContext* _serviceContext; }; /** @@ -267,7 +264,7 @@ class CollectionCriticalSection { CollectionCriticalSection& operator=(const CollectionCriticalSection&) = delete; public: - CollectionCriticalSection(OperationContext* opCtx, NamespaceString ns); + CollectionCriticalSection(OperationContext* opCtx, NamespaceString nss); ~CollectionCriticalSection(); /** @@ -276,9 +273,9 @@ public: void enterCommitPhase(); private: - NamespaceString _nss; + OperationContext* const _opCtx; - OperationContext* _opCtx; + NamespaceString _nss; }; } // namespace mongo |