[SERVER-40811] Eliminate MONGO_INITIALIZER kruft Created: 24/Apr/19  Updated: 06/Dec/22  Resolved: 08/Dec/20

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: Needs Further Definition
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Backlog - Service Architecture
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-47778 have MONGO_INITIALIZERs throw to indi... Closed
is duplicated by SERVER-43077 problems with MONGO_MODULE_STARTUP_OP... Closed
Issue split
split to SERVER-47778 have MONGO_INITIALIZERs throw to indi... Closed
Assigned Teams:
Service Arch
Sprint: Dev Tools 2019-05-20, Dev Tools 2019-06-03, Dev Tools 2019-06-17, Dev Tools 2019-09-09
Participants:

 Description   

MONGO_INITIALIZER has some unnecessary API complexity.

We don't need:
MONGO_INITIALIZER_WITH_PREREQUISITES
MONGO_INITIALIZER_GENERAL.

`MONGO_INITIALIZER` can instead take a name and 2 optional parameters.

MONGO_INITIALIZER(name)
MONGO_INITIALIZER(name,prereqs)
MONGO_INITIALIZER(name,prereqs,dependents)

The preprocessor can handle this with a `_VA_ARGS_` arity selector idiom.

We do not need the make_string_vector.h,cpp files at all.
We can remove parens from prereqs and dependents preprocessor-tuples with the preprocessor, and rely on vector<string> to brace-init in place.
This would eliminate the need to have the primitive NULL-terminated va_arg list API.

We can just have the MONGO_INITIALIZER macro directly create `vector<string>` to give the registration API as temporaries and we can more gracefully handle empty lists as () instead of (NULL). At that point we don't need the MONGO_NO_PREREQUISITES or MONGO_NO_DEPENDENTS macros because the `()` is easier to remember than `(NULL)`.



 Comments   
Comment by Billy Donahue [ 09/Dec/20 ]

That commit was intended to be labeled with SERVER-47778.

Comment by Githook User [ 08/Dec/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-40811 make initializers throwy

Comment by Billy Donahue [ 14/Jun/19 ]

Steps:

  • Convert initializers to be throwy, instead of returning Status.
    Most of the time they just return OK unconditionally, and that's easier to say with an exception protocol.
  • Collapse the MONGO_INITIALIZER_* macros into a single MONGO_INITIALIZER macro.
  • Get rid of the MONGO_INITIALIZER macro, in favor of a builder that makes an initializer registration call.
    These call builders still have to run at file-static scope, but I think a more generic utility should handle that.

Something like what java has with static initialization blocks.

MONGO_STATIC_INITIALIZER {
    ... code ...
}

Then lots of code can be grouped together into the MONGO_STATIC_INITIALIZER block. We wouldn't need a separate dummy per globally initialized thing, and we wouldn't need a macro for each kind of static-init dummy (MONGO_INITIALIZERs are just one of several kinds of things registered at static init time).

Possible Implementation. It's the same trick as MONGO_INITIALIZER uses now, essentially, but without the initializer-specifics.

#define MONGO_ANON_FUNC AnonFunc##__LINE__
#define MONGO_STATIC_INITIALIZER \
    static void MongoStaticallyFunc##MONGO_ANON (); \
    static const bool MongoStaticallyDummy##MONGO_ANON = (MongoStatically##MONGO_ANON_FUNC (), false);
    static MongoStaticallyFunc##MONGO_ANON ()

Comment by Githook User [ 16/May/19 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-40811 reduce GlobalInitializerRegisterer constructors
Branch: master
https://github.com/mongodb/mongo/commit/8c4f95e45b8cf32c61f73bc4e2dd3beaa97e190c

Comment by Githook User [ 30/Apr/19 ]

Author:

{'name': 'Billy Donahue', 'username': 'BillyDonahue', 'email': 'billy.donahue@mongodb.com'}

Message: SERVER-40811 refactor to show nesting of startup option init groups
Branch: master
https://github.com/mongodb/mongo/commit/5b29bae61192a3a449d729691b1765bb4ade3dea

Comment by Billy Donahue [ 29/Apr/19 ]

This review went much further, into replacing MONGO_INITIALIZER altogether with a builder pattern.
And into changing the init functions to be exception-based.

Will put off any pursuit of this until at least post v4.2, as it affects a lot of code with hand-edits.

Generated at Thu Feb 08 04:56:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.