diff options
author | Ben Caimano <ben.caimano@mongodb.com> | 2019-11-05 00:10:46 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-05 00:10:46 +0000 |
commit | 20851234f3afa84a40d22ffe28a991a6c8b91e02 (patch) | |
tree | 8d44f3ce967f005b92c035d902d6de34757c533f | |
parent | 0a2d9378a71eaf5a423b4efba715ebf335535141 (diff) | |
download | mongo-20851234f3afa84a40d22ffe28a991a6c8b91e02.tar.gz |
SERVER-44322 Fail gracefully when the storage engine has failed to initialize
This commit is only on v3.6 as an alternative to a full backport of SERVER-34798.
-rw-r--r-- | src/mongo/db/service_context.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/service_context_d.cpp | 7 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp index 25c84c48882..719f2c2dadb 100644 --- a/src/mongo/db/service_context.cpp +++ b/src/mongo/db/service_context.cpp @@ -28,6 +28,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + #include "mongo/platform/basic.h" #include "mongo/db/service_context.h" @@ -41,6 +43,7 @@ #include "mongo/transport/session.h" #include "mongo/transport/transport_layer.h" #include "mongo/util/assert_util.h" +#include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" #include "mongo/util/system_clock_source.h" #include "mongo/util/system_tick_source.h" @@ -93,7 +96,11 @@ bool supportsDocLocking() { bool isMMAPV1() { StorageEngine* globalStorageEngine = getGlobalServiceContext()->getGlobalStorageEngine(); - invariant(globalStorageEngine); + if (!globalStorageEngine) { + warning() + << "Attempted to check if storage engine is MMAPv1 without an existing storage engine."; + return false; + } return globalStorageEngine->isMmapV1(); } diff --git a/src/mongo/db/service_context_d.cpp b/src/mongo/db/service_context_d.cpp index d3be43d88ed..7fbb189194d 100644 --- a/src/mongo/db/service_context_d.cpp +++ b/src/mongo/db/service_context_d.cpp @@ -268,13 +268,16 @@ std::unique_ptr<OperationContext> ServiceContextMongoD::_newOpCtx(Client* client invariant(&cc() == client); auto opCtx = stdx::make_unique<OperationContext>(client, opId); - if (isMMAPV1()) { + auto globalStorageEngine = getGlobalStorageEngine(); + invariant(globalStorageEngine); + + if (globalStorageEngine->isMmapV1()) { opCtx->setLockState(stdx::make_unique<MMAPV1LockerImpl>()); } else { opCtx->setLockState(stdx::make_unique<DefaultLockerImpl>()); } - opCtx->setRecoveryUnit(getGlobalStorageEngine()->newRecoveryUnit(), + opCtx->setRecoveryUnit(globalStorageEngine->newRecoveryUnit(), OperationContext::kNotInUnitOfWork); return opCtx; } |