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

Improve implementation of mongo::Status

    • Fully Compatible
    • Service arch 2020-12-28, Service Arch 2021-03-08, Service Arch 2021-03-22, Service Arch 2021-04-05, Service Arch 2021-04-19, Service Arch 2021-05-17, Service Arch 2021-05-31, Service Arch 2021-06-14, Service Arch 2021-06-28, Service Arch 2021-07-12, Service Arch 2021-08-09, Service Arch 2021-08-23, Service Arch 2021-09-20
    • 1

      Status has a lot of old code that needs a facelift.

      (started as follow-on work from SERVER-52741)

      Use boost::intrusive_ptr instead of handrolled refcounting for _error member.
      This eliminates the need for copy and move ctors, assigns, and the destructor.

      Don't declare operator<< for StringBuilderImpl that we don't define.

      Inline the ubiquitous Status::OK() function.
      Inline most constructors. Usually they forward to another constructor.

      Define inlines inside the class consistently. This was previously mixed and inconsistent. It eliminates a lot of the boilerplate from out-of-class definitions.

      Pass reason by std::string value when possible to save string copies!

      Accept anything as a reason parameter if it can direct-initialize a std::string. This eliminates fwd decl of std::stream, and eliminates the combinatoric redundancy of providing overloads for const char*, StringData, std::string, and std::stream, which also leaves a lot of viable argument types missing anyway.

      Remove useless const from return types and from parameters.

      Use std::is_..._v traits bools.

      Define inline-friend-defs for all == and != operators so they are applied symmetrically, and are only visible to ADL search.

      Allocate the empty reason() static local string so it is valid at shutdown.

      Remove the refCount() member, replace with a testOnlyAccess() proxy object that can retrieve the same data, but more obviously and strictly test only.

      Simplify ErrorInfo to a simple struct, inherit from boost::intrusive_ref_counter. No explicit atomics for refcounting, no const members, no member functions. Let Status enforce the constness and creation invariants. Status::ErrorInfo becomes just plain info.

      Add static Status::_createErrorInfo and Status::_parseErrorInfo functions to produce intrusive_ptr to initialize the _error member from constructors. Get rid of the risky *this = someStatus... error handling in favor of these functions.

      https://mongodbcr.appspot.com/709190050/

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

              Created:
              Updated:
              Resolved: