Weird operation in db.currentOp() output in MongoDB

Viewed 442

Just after starting my MongoDB server (standalone instance, version 4.2.2) if I run db.currentOp() I see this operation:

    {
        "type" : "op",
        "host" : "menzo:27017",
        "desc" : "waitForMajority",
        "active" : true,
        "currentOpTime" : "2020-05-06T16:16:33.077+0200",
        "opid" : 2,
        "op" : "none",
        "ns" : "",
        "command" : {

        },
        "numYields" : 0,
        "waitingForLatch" : {
            "timestamp" : ISODate("2020-05-06T14:02:55.895Z"),
            "captureName" : "WaitForMaorityService::_mutex"
        },
        "locks" : {

        },
        "waitingForLock" : false,
        "lockStats" : {

        },
        "waitingForFlowControl" : false,
        "flowControlStats" : {

        }
    }

It seems that this operation is always there, no matter how long it passes. In addition, it is a weird operation in some aspects:

  • It has a very log opid number (2)
  • It's op is "none"
  • It doesn't have the usual secs_running or microsecs_running parameters
  • It mentions "majority" in some literals, but I'm not running a replica set but an standalone instance

I guess it should be some kind of internal operation (maybe a kind of "waiting thread"?) but I haven't found documentation about it in the currentOp command documentation.

Do anybody knows about this operation and/or could point to documentation where it is described, please? Thanks in advance!

1 Answers

Wait for majority service is defined here. Looking at the history of this file, it appears to have been added as part of work on improving startup performance.

Reading the ticket description, it seems that during startup, multiple operations may need to wait for a majority commit. Previously each may have created a separate thread for waiting; with the majority wait service, there is only one thread which is waiting for the most recent required commit.

Therefore:

It's op is "none"

The thread isn't performing an operation as defined in the docs.

It has a very log opid number (2)

This is because this thread is started when the server starts.

It mentions "majority" in some literals, but I'm not running a replica set but an standalone instance

It is possible to instruct mongod to run in replica set mode and point it at a data directory created by a standalone node, and vice versa. In these cases you'd probably expect the process to preserve the information already in the database, such as transactions that are pending (or need to be aborted). Hence the startup procedure may perform operations not intuitively falling under the operation mode requested.

Related