From af600c3876a26f62d8dde93bf769fc4ca3054072 Mon Sep 17 00:00:00 2001 From: Henrik Edin Date: Mon, 12 Mar 2018 11:14:15 -0400 Subject: SERVER-30170 Embedded can now shutdown and re-initialize. - ServiceContext* is now closer to be an instance context for the database. We still don't support multiple instances but I wrote the new code with this in mind. Teardown and reinitialize then becomes a matter of being able to delete and re-create the ServiceContext*. - Use the new MONGO_INITIALIZER that supports deinit/reinit to be able to re-initialize global systems that are decorations on ServiceContext. - Move creation/destruction of ServiceContext* out of MONGO_INITIALIZER. This so we can hold an exclusive lock during as much as possible of the shutdown (like how mongod does) - New ServiceContext registrer where we can link in different implementations of ServiceContext (replaces the SetGlobalEnvironment MONGO_INITIALIZER) - As a result the SetGlobalEnvironment prerequisite for MONGO_INITIALIZERs is gone. - The ServiceContext is passed to runGlobalInitializers, put in InitializationContext/DeinitializationContext so the initializers know which context they operate on. --- src/mongo/tools/bridge.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/mongo/tools') diff --git a/src/mongo/tools/bridge.cpp b/src/mongo/tools/bridge.cpp index 375c88bbc1b..5e5fcbf7417 100644 --- a/src/mongo/tools/bridge.cpp +++ b/src/mongo/tools/bridge.cpp @@ -39,6 +39,7 @@ #include "mongo/db/dbmessage.h" #include "mongo/db/service_context.h" #include "mongo/db/service_context_noop.h" +#include "mongo/db/service_context_registrar.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/random.h" #include "mongo/rpc/command_request.h" @@ -391,10 +392,9 @@ private: std::unique_ptr listener; -MONGO_INITIALIZER(SetGlobalEnvironment)(InitializerContext* context) { - setGlobalServiceContext(stdx::make_unique()); - return Status::OK(); -} +ServiceContextRegistrar serviceContextCreator([]() { + return std::make_unique(); +}); } // namespace @@ -409,7 +409,8 @@ int bridgeMain(int argc, char** argv, char** envp) { }); setupSignalHandlers(); - runGlobalInitializersOrDie(argc, argv, envp); + setGlobalServiceContext(createServiceContext()); + runGlobalInitializersOrDie(argc, argv, envp, getGlobalServiceContext()); startSignalProcessingThread(LogFileStatus::kNoLogFileToRotate); auto serviceContext = getGlobalServiceContext(); -- cgit v1.2.1