Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-47778

have MONGO_INITIALIZERs throw to indicate failure

    • Fully Compatible
    • 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

      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));
      

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: