[SERVER-5112] Need a better story for startup-time initialization of C++ modules. Created: 27/Feb/12 Updated: 11/Jul/16 Resolved: 15/Oct/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Code |
| Affects Version/s: | None |
| Fix Version/s: | 2.3.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Andy Schwerin | Assignee: | Andy Schwerin |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
Static initializers don't work in the end, because there's no way to specify ordering dependences. The code is slowly amassing a hodgepodge of alternatives, including singleton objects initialized at first access, using a hand-written double-check locking pattern. A better solution would be to allow programmers to declare "init functions" for modules, and to list their dependencies in their declaration. Then, at the top of main(), mongo programs would call InitMongo(), which would execute the init functions in top-sort order. Implementations I've used in the past have declared init functions using a macro:
Further, you can declare nodes in the dependency graph to aggregate things. For example, if you need to run some code after all global foo objects are initialized, you can have a macro for declaring global foo objects that makes their initialization code out-depend on "foos_initialized", a noop node. Then, your code that depends on "all foos are initialized" can just have an input dependency on "foos_initialized", and doesn't need to explicitly be able to name all instances of "foo". |
| Comments |
| Comment by auto [ 26/Sep/12 ] |
|
Author: {u'date': u'2012-09-13T07:59:15-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: Call runGlobalInitializersOrDie() at the top of the main() functions in mongo programs.
|
| Comment by auto [ 25/Sep/12 ] |
|
Author: {u'date': u'2012-09-17T09:19:26-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: These utilities simplify adding global (process-wide) initializers that run at the beginning of Also, run the global initializers in the main() of unittests. |
| Comment by auto [ 25/Sep/12 ] |
|
Author: {u'date': u'2012-09-13T08:54:44-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: |
| Comment by auto [ 25/Sep/12 ] |
|
Author: {u'date': u'2012-09-13T07:43:47-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: Stringify the cycle into the Status message parameter when topSort detects a cycle. Should improve reporting of programming errors involving initialization dependences.
|
| Comment by auto [ 25/Sep/12 ] |
|
Author: {u'date': u'2012-09-11T13:59:48-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: In this implementation, setVariable function always takes a string |
| Comment by auto [ 25/Sep/12 ] |
|
Author: {u'date': u'2012-09-13T07:41:38-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: Rename InitializationContext to InitializerContext, for consistency with other type names.
|
| Comment by auto [ 17/Sep/12 ] |
|
Author: {u'date': u'2012-09-10T07:35:08-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: Implement and test InitializerDependencyGraph. An InitializerDependencyGraph is a directed acyclic graph (DAG) of named InitializerDependencyGraph is exception-free, and because it is for use very This patch also introduces a utility macro, MONGO_MAKE_STRING_VECTOR, which is Part of work on |
| Comment by auto [ 17/Jul/12 ] |
|
Author: {u'date': u'2012-07-16T15:48:37-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: Link programs by linking all object files on the command line. This is done rather than enumerating a list of static libraries to include.
|
| Comment by auto [ 17/Jul/12 ] |
|
Author: {u'date': u'2012-07-16T15:48:37-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: Link programs by linking all object files on the command line. This is done rather than enumerating a list of static libraries to include.
|
| Comment by auto [ 17/Jul/12 ] |
|
Author: {u'date': u'2012-07-16T15:43:56-07:00', u'email': u'schwerin@10gen.com', u'name': u'Andy Schwerin'}Message: Break a few more libraries off of "mongocommon". Supports building all build products using _LIBDEPS=_LIBDEPS_OBJS instead of Necessitated in the short term by |
| Comment by Tad Marshall [ 07/Jun/12 ] |
|
Another item to initialize at startup time: Windows memory allocation granularity, fetched with the GetSystemInfo() API (along with other elements). See |