diff options
author | Randolph Tan <randolph@mongodb.com> | 2019-10-23 16:07:44 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-23 16:07:44 +0000 |
commit | e0f6fdab23da872d9cf8a93b88c2332ba45041c0 (patch) | |
tree | 5de76e8d4b51439c162e25ede990282206514da2 /src/mongo/db/db_raii.cpp | |
parent | a81740843b21c8dcff964bd0a168e9da7cc5225d (diff) | |
download | mongo-e0f6fdab23da872d9cf8a93b88c2332ba45041c0.tar.gz |
SERVER-42737 Make secondary reads in ShardServerCatalogCacheLoader block behind the PBW lock
Diffstat (limited to 'src/mongo/db/db_raii.cpp')
-rw-r--r-- | src/mongo/db/db_raii.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index ede268a31f3..4e2fc2c8e45 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -46,6 +46,12 @@ namespace { const boost::optional<int> kDoNotChangeProfilingLevel = boost::none; +// TODO: SERVER-44105 remove +// If set to false, secondary reads should wait behind the PBW lock. +// Does nothing if gAllowSecondaryReadsDuringBatchApplication setting is false. +const auto allowSecondaryReadsDuringBatchApplication_DONT_USE = + OperationContext::declareDecoration<boost::optional<bool>>(); + } // namespace AutoStatsTracker::AutoStatsTracker(OperationContext* opCtx, @@ -92,6 +98,7 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, // Don't take the ParallelBatchWriterMode lock when the server parameter is set and our // storage engine supports snapshot reads. if (gAllowSecondaryReadsDuringBatchApplication.load() && + allowSecondaryReadsDuringBatchApplication_DONT_USE(opCtx).value_or(true) && opCtx->getServiceContext()->getStorageEngine()->supportsReadConcernSnapshot()) { _shouldNotConflictWithSecondaryBatchApplicationBlock.emplace(opCtx->lockState()); } @@ -388,4 +395,18 @@ LockMode getLockModeForQuery(OperationContext* opCtx, const boost::optional<Name return MODE_IS; } +BlockSecondaryReadsDuringBatchApplication_DONT_USE:: + BlockSecondaryReadsDuringBatchApplication_DONT_USE(OperationContext* opCtx) + : _opCtx(opCtx) { + auto allowSecondaryReads = &allowSecondaryReadsDuringBatchApplication_DONT_USE(opCtx); + allowSecondaryReads->swap(_originalSettings); + *allowSecondaryReads = false; +} + +BlockSecondaryReadsDuringBatchApplication_DONT_USE:: + ~BlockSecondaryReadsDuringBatchApplication_DONT_USE() { + auto allowSecondaryReads = &allowSecondaryReadsDuringBatchApplication_DONT_USE(_opCtx); + allowSecondaryReads->swap(_originalSettings); +} + } // namespace mongo |