summaryrefslogtreecommitdiff
path: root/src/mongo/db/db_raii.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/db_raii.cpp')
-rw-r--r--src/mongo/db/db_raii.cpp21
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