-
Type: New Feature
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Internal Code
This ticket is the dual of SERVER-5112. The result of SERVER-5112 is that the server has a very explicit initialization system that ensures a well defined initialization order. Each subsystem can define its own startup code, and specify exactly what it depends on and what depends on it. In particular, this solved the "static initialization order" issue, in which constructors for statically defined classes run in an undefined order at before main() gets called.
The shutdown process needs similar attention. There is some "shutdown" code that needs to be run when the server is shutting down. However, this code is often run implicitly in destructors, or is lumped all together with process exit.
To start, we have duplicated definitions of the "dbexit" function, which is the entry point to the shutdown system.
One for mongos:
https://github.com/mongodb/mongo/blob/master/src/mongo/s/server.cpp#L448
And one for mongod:
https://github.com/mongodb/mongo/blob/master/src/mongo/db/instance.cpp#L1135
This function is the entry to point to the current shutdown process in the server. The fact that these signatures are identical (and used from some libraries that both mongod and mongos share) and have diverged shows that the shutdown process has not been properly factored out. "server.cpp" is the main() for mongos, and "instance.cpp" is a legacy file with old file and process related code.
There is also an "inShutdown" function, of which there are also multiple definitions:
mongod:
https://github.com/mongodb/mongo/blob/master/src/mongo/db/instance.cpp#L1135
mongos:
https://github.com/mongodb/mongo/blob/master/src/mongo/s/server.cpp#L103
This function is effectively in place as a way to notify other parts of the server that we are shutting down. However, this function is not thread safe, and it is not clear when this call is needed. This could potentially be replaced by some more explicit notification of the various components that need to be notified of shutdown.
Finally, the "dbexit" call, in addition to shutting down the database components, also exits the process. This lack of separation is a problem specifically for the tools, since some tools internally start up a database server to enable the "--dbpath" direct data file access functionality. This means that when the server gets shut down, the process exits which means the tools have limited control over how the process exits in this case. See SERVER-9473, SERVER-8064, and SERVER-1994.
- depends on
-
SERVER-5773 mongo::PeriodicTask::Runner cleanup
- Closed
-
CXX-103 It must be OK to run the destructors for static objects created by the C++ driver
- Closed
-
SERVER-5703 ntservice should not have to fake out exitCleanly() to achieve its ends
- Closed
-
SERVER-5868 Should consolidate to a single implementation of main()
- Closed
- is depended on by
-
SERVER-8707 dbclient_rs_test threading issue
- Closed
-
TOOLS-11 mongodump exits with success despite 'no space left on device' error
- Closed
-
TOOLS-161 Have tools always exit with non-zero exit code on error
- Closed
- related to
-
SERVER-15096 Create standalone tool to read/write directly from stored format
- Closed