Search code examples
mongodbreplicasetmongodb-replica-set

In which state a MongoDB replica set node ends if it cannot find a majority during a primary election?


Let's consider a MongoDB replica set composed of three nodes (Node 1 being the primary, Node 2 and 3 being secondaries) and a network partition occurs, so Node 1 lose connection to 2 and 3 (but 2 and 3 are connected each other).

enter image description here

So, at the end Node2 and Node3 will elect a new primary (as they have a majority of nodes in their partition). So one of them (depending on priority, votes and oplog time) will end as PRIMARY and the other as SECONDARY.

However, when the old primary (Node 1) realizes that it is no longer a primary, to which state it will transition? I don't refer to the state from the point of view of Node 2 or 3 (that I guess will see Node1 as DOWN) but the state that Node 1 sees itself.

I have looked to replica set states in MongoDB official documentation but I haven't found an clear answer there.

Thanks!


Solution

  • Each of the nodes keeps track of the current status of the other replica set members via heartbeat. Around the time nodes 2 and 3 realize that node 1 isn't responding to them, node 1 will realize that nodes 2 and 3 are not responding to it, so it should log something along the lines of

    can't see a majority of the set, relinquishing primary

    And then it will transition to secondary.