From 90d6271d2f663a4aaf633de5e362972e50e90c21 Mon Sep 17 00:00:00 2001 From: Gregory Wlodarek Date: Fri, 22 Apr 2022 19:42:03 +0000 Subject: SERVER-60761 Move the global read-only flag to be an OperationContext function --- src/mongo/embedded/embedded.cpp | 15 +++++++++------ src/mongo/embedded/embedded_ismaster.cpp | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/mongo/embedded') diff --git a/src/mongo/embedded/embedded.cpp b/src/mongo/embedded/embedded.cpp index 20395926254..eb2549573b5 100644 --- a/src/mongo/embedded/embedded.cpp +++ b/src/mongo/embedded/embedded.cpp @@ -234,6 +234,13 @@ ServiceContext* initialize(const char* yaml_config) { serviceContext, serviceContext->getPreciseClockSource()); serviceContext->setPeriodicRunner(std::move(periodicRunner)); + // When starting the server with --queryableBackupMode or --recoverFromOplogAsStandalone, we are + // in read-only mode and don't allow user-originating operations to perform writes + if (storageGlobalParams.queryableBackupMode || + repl::ReplSettings::shouldRecoverFromOplogAsStandalone()) { + serviceContext->disallowUserWrites(); + } + setUpCatalog(serviceContext); // Creating the operation context before initializing the storage engine allows the storage @@ -278,15 +285,11 @@ ServiceContext* initialize(const char* yaml_config) { uassert(50677, ss.str().c_str(), boost::filesystem::exists(storageGlobalParams.dbpath)); } - if (!storageGlobalParams.readOnly) { - boost::filesystem::remove_all(storageGlobalParams.dbpath + "/_tmp/"); - } + boost::filesystem::remove_all(storageGlobalParams.dbpath + "/_tmp/"); ReadWriteConcernDefaults::create(serviceContext, readWriteConcernDefaultsCacheLookupEmbedded); - bool canCallFCVSetIfCleanStartup = - !storageGlobalParams.readOnly && !(storageGlobalParams.engine == "devnull"); - if (canCallFCVSetIfCleanStartup) { + if (storageGlobalParams.engine != "devnull") { Lock::GlobalWrite lk(startupOpCtx.get()); FeatureCompatibilityVersion::setIfCleanStartup(startupOpCtx.get(), repl::StorageInterface::get(serviceContext)); diff --git a/src/mongo/embedded/embedded_ismaster.cpp b/src/mongo/embedded/embedded_ismaster.cpp index 6b9903f35ca..a9f6763952e 100644 --- a/src/mongo/embedded/embedded_ismaster.cpp +++ b/src/mongo/embedded/embedded_ismaster.cpp @@ -87,7 +87,7 @@ public: result.append("minWireVersion", wireSpec->incomingExternalClient.minWireVersion); result.append("maxWireVersion", wireSpec->incomingExternalClient.maxWireVersion); - result.append("readOnly", storageGlobalParams.readOnly); + result.append("readOnly", opCtx->readOnly()); return true; } -- cgit v1.2.1