[SERVER-47778] have MONGO_INITIALIZERs throw to indicate failure Created: 27/Apr/20  Updated: 29/Oct/23  Resolved: 08/Dec/20

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Improvement Priority: Minor - P4
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 1
Labels: servicearch-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-40811 Eliminate MONGO_INITIALIZER kruft Closed
is duplicated by SERVER-43078 Make MONGO_INITIALIZER functions thro... Closed
Issue split
split from SERVER-40811 Eliminate MONGO_INITIALIZER kruft Closed
Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2020-07-27, Service Arch 2020-08-10, Service Arch 2020-08-24, Service arch 2020-09-07, Service arch 2020-09-21, Service arch 2020-12-14
Participants:

 Description   

Convert initializers to throw DBException if something goes wrong, instead of returning Status. Most of the time they just return OK unconditionally, and that's easier to say with an exception protocol.

If any initializer returns a non-OK status, all initialization stops. Basically the process dies right away, and it's a gracefully fatal error to return non-OK status. Most initializers today have a single Status::OK() return statement, providing no information. It's unnecessary.

A simple change (already done) replaces all INITIALIZER return Status::OK(), or just deleting it if it's the last statement of the function. All non-OK `return expr` can be replaced with `uassertStatusOK(expr)`.  There are 148 little improvements to make. 
Most are simply removing a boilerplate return statement from a 1-liner like this:

 MONGO_INITIALIZER_GENERAL(ForkServer, ("EndStartupOptionHandling"), ("default"))
 (InitializerContext* context) {
     mongo::forkServerOrDie();
     return Status::OK();  // <== remove this
 }

but more substantial code is improved as well:

auto status = insertSingleName(opt._singleName);
if (!status.isOK()) {	
    return status;	
}

becomes

uassertStatusOK(insertSingleName(opt._singleName));



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

The two commits (mongo and enterprise) landed in two other tickets.
There were several attempts at this under different SERVER numbers.
Anyway, consolidating them here as follows.


10gen/mongo-enterprise-modules [master]

Author:

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

Message: SERVER-43078 exceptionize MONGO_INITIALIZER callers
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/bf2a6c0ea2e35e8e776a469db03b89e03f20b5a0


mongodb/mongo [master]

Author:

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

Message: SERVER-40811 make initializers throwy

Consolidate init-related headers (just init.h and initializer.h)
Factor out a separate DependencyGraph component
Remove MONGO_DEFAULT_PREREQUISITES, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS.
Document the role of the "default" initializer.
Branch: master
https://github.com/mongodb/mongo/commit/7c51aca7fd085ead0ae3e19d967ff1abf111d13a

Comment by Billy Donahue [ 01/Dec/20 ]

Revived the code reviews!

Comment by Billy Donahue [ 19/Oct/20 ]

I'm only keeping it open for my own reference. It's not an active code review only because there hasn't been a sprint with capacity to land it.
It would have to be refreshed to land it.

Comment by Billy Donahue [ 27/Apr/20 ]

CR:
https://mongodbcr.appspot.com/573470001

CR (enterprise):
http://mongodbcr.appspot.com/593940001

Generated at Thu Feb 08 05:15:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.