summaryrefslogtreecommitdiff
path: root/src/mongo/db/db.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-02-16 02:04:08 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-26 07:55:48 +0000
commit51eceb8afa6610b4ff0befb92ec6039173bab00f (patch)
tree4725ecdb5d0bec00ac6938cf447c21924297ea56 /src/mongo/db/db.cpp
parent8651c754eedf84651dd5051aa43c70cd96b00586 (diff)
downloadmongo-51eceb8afa6610b4ff0befb92ec6039173bab00f.tar.gz
SERVER-44978 Remove accidentally added usage of getGlobalServiceContext() from ReadWriteConcernDefaults
Diffstat (limited to 'src/mongo/db/db.cpp')
-rw-r--r--src/mongo/db/db.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 970601d929a..886592fe567 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -293,11 +293,10 @@ void initializeCommandHooks(ServiceContext* serviceContext) {
MONGO_FAIL_POINT_DEFINE(shutdownAtStartup);
-ExitCode _initAndListen(int listenPort) {
+ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
Client::initThread("initandlisten");
initWireSpec();
- auto serviceContext = getGlobalServiceContext();
serviceContext->setFastClockSource(FastClockSourceFactory::create(Milliseconds(10)));
@@ -767,9 +766,9 @@ ExitCode _initAndListen(int listenPort) {
return waitForShutdown();
}
-ExitCode initAndListen(int listenPort) {
+ExitCode initAndListen(ServiceContext* service, int listenPort) {
try {
- return _initAndListen(listenPort);
+ return _initAndListen(service, listenPort);
} catch (DBException& e) {
LOGV2(20557, "exception in initAndListen: {e}, terminating", "e"_attr = e.toString());
return EXIT_UNCAUGHT;
@@ -789,7 +788,7 @@ ExitCode initAndListen(int listenPort) {
#if defined(_WIN32)
ExitCode initService() {
- return initAndListen(serverGlobalParams.port);
+ return initAndListen(getGlobalServiceContext(), serverGlobalParams.port);
}
#endif
@@ -1247,18 +1246,23 @@ int mongoDbMain(int argc, char* argv[], char** envp) {
quickExit(EXIT_FAILURE);
}
- try {
- setGlobalServiceContext(ServiceContext::make());
- } catch (...) {
- auto cause = exceptionToStatus();
- LOGV2_FATAL_OPTIONS(20575,
- {logComponentV1toV2(LogComponent::kControl)},
- "Failed to create service context: {cause}",
- "cause"_attr = redact(cause));
- quickExit(EXIT_FAILURE);
- }
+ auto* service = [] {
+ try {
+ auto serviceContextHolder = ServiceContext::make();
+ auto* serviceContext = serviceContextHolder.get();
+ setGlobalServiceContext(std::move(serviceContextHolder));
+
+ return serviceContext;
+ } catch (...) {
+ auto cause = exceptionToStatus();
+ LOGV2_FATAL_OPTIONS(20575,
+ {logComponentV1toV2(LogComponent::kControl)},
+ "Failed to create service context: {cause}",
+ "cause"_attr = redact(cause));
+ quickExit(EXIT_FAILURE);
+ }
+ }();
- auto service = getGlobalServiceContext();
setUpCollectionShardingState(service);
setUpCatalog(service);
setUpReplication(service);
@@ -1289,7 +1293,7 @@ int mongoDbMain(int argc, char* argv[], char** envp) {
}
#endif
- ExitCode exitCode = initAndListen(serverGlobalParams.port);
+ ExitCode exitCode = initAndListen(service, serverGlobalParams.port);
exitCleanly(exitCode);
return 0;
}