summaryrefslogtreecommitdiff
path: root/src/mongo/db/service_context.h
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2022-04-22 19:42:03 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-22 20:12:32 +0000
commit90d6271d2f663a4aaf633de5e362972e50e90c21 (patch)
treed24da0cee090d7d92972fa8f43fa4f0eb41ac915 /src/mongo/db/service_context.h
parent983a7174c6d792049ef0f54e36a55f93801df89c (diff)
downloadmongo-90d6271d2f663a4aaf633de5e362972e50e90c21.tar.gz
SERVER-60761 Move the global read-only flag to be an OperationContext function
Diffstat (limited to 'src/mongo/db/service_context.h')
-rw-r--r--src/mongo/db/service_context.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h
index 44e12901cea..10dd5e33203 100644
--- a/src/mongo/db/service_context.h
+++ b/src/mongo/db/service_context.h
@@ -603,6 +603,24 @@ public:
_catalogGeneration.fetchAndAdd(1);
}
+ void disallowUserWrites() {
+ _userWritesAllowed.store(false);
+ }
+
+ /**
+ * Returns true if user writes are allowed.
+ *
+ * User writes are disallowed when starting with queryableBackupMode or
+ * recoverFromOplogAsStandalone to prevent users from writing to replicated collections in
+ * standalone mode.
+ *
+ * To determine whether an operation must run in read-only mode, use
+ * OperationContext::readOnly().
+ */
+ bool userWritesAllowed() const {
+ return _userWritesAllowed.load();
+ }
+
LockedClient getLockedClient(OperationId id);
private:
@@ -749,6 +767,9 @@ private:
// When the catalog is restarted, the generation goes up by one each time.
AtomicWord<uint64_t> _catalogGeneration{0};
+ // Server-wide flag indicating whether users' writes are allowed.
+ AtomicWord<bool> _userWritesAllowed{true};
+
bool _startupComplete = false;
stdx::condition_variable _startupCompleteCondVar;
};