summaryrefslogtreecommitdiff
path: root/src/mongo/s/server.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2018-03-12 11:14:15 -0400
committerHenrik Edin <henrik.edin@mongodb.com>2018-03-26 15:54:16 -0400
commitaf600c3876a26f62d8dde93bf769fc4ca3054072 (patch)
treeecef32a9b3c6c54501651168cce48093e76e9858 /src/mongo/s/server.cpp
parent2676a176759359c8614c0e37b267198259b6789f (diff)
downloadmongo-af600c3876a26f62d8dde93bf769fc4ca3054072.tar.gz
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.
Diffstat (limited to 'src/mongo/s/server.cpp')
-rw-r--r--src/mongo/s/server.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 449f51389db..cedcf00ff64 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -61,6 +61,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_noop.h"
+#include "mongo/db/service_context_registrar.h"
#include "mongo/db/session_killer.h"
#include "mongo/db/startup_warnings_common.h"
#include "mongo/db/wire_version.h"
@@ -549,13 +550,14 @@ MONGO_INITIALIZER(CreateAuthorizationExternalStateFactory)(InitializerContext* c
return Status::OK();
}
-MONGO_INITIALIZER(SetGlobalEnvironment)(InitializerContext* context) {
- setGlobalServiceContext(stdx::make_unique<ServiceContextNoop>());
- getGlobalServiceContext()->setTickSource(stdx::make_unique<SystemTickSource>());
- getGlobalServiceContext()->setFastClockSource(stdx::make_unique<SystemClockSource>());
- getGlobalServiceContext()->setPreciseClockSource(stdx::make_unique<SystemClockSource>());
- return Status::OK();
-}
+ServiceContextRegistrar serviceContextCreator([]() {
+ auto service = std::make_unique<ServiceContextNoop>();
+ service->setTickSource(std::make_unique<SystemTickSource>());
+ service->setFastClockSource(std::make_unique<SystemClockSource>());
+ service->setPreciseClockSource(std::make_unique<SystemClockSource>());
+ return service;
+});
+
#ifdef MONGO_CONFIG_SSL
MONGO_INITIALIZER_GENERAL(setSSLManagerType, MONGO_NO_PREREQUISITES, ("SSLManager"))
@@ -577,7 +579,8 @@ ExitCode mongoSMain(int argc, char* argv[], char** envp) {
setupSignalHandlers();
- Status status = runGlobalInitializers(argc, argv, envp);
+ setGlobalServiceContext(createServiceContext());
+ Status status = runGlobalInitializers(argc, argv, envp, getGlobalServiceContext());
if (!status.isOK()) {
severe(LogComponent::kDefault) << "Failed global initialization: " << status;
return EXIT_ABRUPT;