diff options
author | jannaerin <golden.janna@gmail.com> | 2018-06-22 16:00:40 -0400 |
---|---|---|
committer | jannaerin <golden.janna@gmail.com> | 2018-06-28 11:25:05 -0400 |
commit | 019264f0277a8ea675a97ed88370bda064923651 (patch) | |
tree | 46119703e49ec2233c7c4037796105ec0eadbcf5 /src/mongo/db/s/collection_sharding_state.cpp | |
parent | d25e202d141fdda3d6f86a4afcec04f76bf7e249 (diff) | |
download | mongo-019264f0277a8ea675a97ed88370bda064923651.tar.gz |
SERVER-35723 Make the collection critical section into an RAII class
Diffstat (limited to 'src/mongo/db/s/collection_sharding_state.cpp')
-rw-r--r-- | src/mongo/db/s/collection_sharding_state.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/s/collection_sharding_state.cpp b/src/mongo/db/s/collection_sharding_state.cpp index fc925d5d153..ebbfc83891b 100644 --- a/src/mongo/db/s/collection_sharding_state.cpp +++ b/src/mongo/db/s/collection_sharding_state.cpp @@ -387,4 +387,21 @@ boost::optional<ChunkRange> CollectionShardingState::getNextOrphanRange(BSONObj return _metadataManager->getNextOrphanRange(from); } +CollectionCriticalSection::CollectionCriticalSection(OperationContext* opCtx, NamespaceString ns) + : _nss(std::move(ns)), _opCtx(opCtx) { + AutoGetCollection autoColl(_opCtx, _nss, MODE_IX, MODE_X); + CollectionShardingState::get(opCtx, _nss)->enterCriticalSectionCatchUpPhase(_opCtx); +} + +CollectionCriticalSection::~CollectionCriticalSection() { + UninterruptibleLockGuard noInterrupt(_opCtx->lockState()); + AutoGetCollection autoColl(_opCtx, _nss, MODE_IX, MODE_X); + CollectionShardingState::get(_opCtx, _nss)->exitCriticalSection(_opCtx); +} + +void CollectionCriticalSection::enterCommitPhase() { + AutoGetCollection autoColl(_opCtx, _nss, MODE_IX, MODE_X); + CollectionShardingState::get(_opCtx, _nss)->enterCriticalSectionCommitPhase(_opCtx); +} + } // namespace mongo |