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-28 07:38:54 +0000 |
commit | f09370cae16ef7d2994332172ee022101186e0ad (patch) | |
tree | e2b0e65dd9d2566726f0301db81e80965dedccef /src/mongo/db/s | |
parent | 23fff6621a57dbfd088e42078b11b9e2ef0a7810 (diff) | |
download | mongo-f09370cae16ef7d2994332172ee022101186e0ad.tar.gz |
SERVER-48401 Ensure the CSR lock has the correct namespace
(cherry picked from commit 764b77bfe24784e740527b167c0a21d22842af30)
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime.h | 18 |
2 files changed, 18 insertions, 19 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index 2e29d85ca42..11d23601102 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -99,16 +99,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()) { - 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) { @@ -418,8 +417,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 3d22f8e8240..432591fb03d 100644 --- a/src/mongo/db/s/collection_sharding_runtime.h +++ b/src/mongo/db/s/collection_sharding_runtime.h @@ -48,7 +48,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); @@ -186,6 +186,9 @@ private: boost::optional<ScopedCollectionDescription> _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; @@ -200,15 +203,12 @@ private: // Tracks the migration critical section state for this collection. 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. // @@ -228,7 +228,7 @@ class CollectionCriticalSection { CollectionCriticalSection& operator=(const CollectionCriticalSection&) = delete; public: - CollectionCriticalSection(OperationContext* opCtx, NamespaceString ns); + CollectionCriticalSection(OperationContext* opCtx, NamespaceString nss); ~CollectionCriticalSection(); /** @@ -237,9 +237,9 @@ public: void enterCommitPhase(); private: - NamespaceString _nss; + OperationContext* const _opCtx; - OperationContext* _opCtx; + NamespaceString _nss; }; } // namespace mongo |