Election process in Replica sets
2 min readJun 1, 2021
In this blog, we will understand the election process in replica sets.
- If the PRIMARY node is down, Replica sets, use election process to determine which member will become a PRIMARY node.
PS: You can make the PRIMARY node inactive by using this command
rs.stepDown()
If you specify a non-numeric value in the parameter, the command uses 60 seconds as default.
- The median time before a cluster elects a new primary should not typically exceed 12 seconds.
- a replica set can have up to 50 members, out of which it can have a max of 7 voting members and a max of 43
non-voting members.
- Members can vote or cannot vote, depending on the votes field value that is set.
rs.conf().members[x].votes = 1; // member can vote
rs.conf().members[x].votes = 0; // member cannot vote
- Members can or cannot become a PRIMARY node, depending on the priority field value that is set.
rs.conf().members[x].priority = 1; // member can become PRIMARY
rs.conf().members[x].priority = 0; // member cannot become PRIMARY
Voting Members:
- Voting members can participate in the election process and can become a PRIMARY node and must have a priority of > 0.
- Only voting members with priority > 0 must be in PRIMARY, SECONDARY, STARTUP2, RECOVERING, ARBITER, ROLLBACK states to participate in the elections.
Please refer to this link for complete details about the Replica Member states.
- You can type the below command and it should be in the above-mentioned state.
>rs.conf().members
//this command is entered on PRIMARY node{
"_id" : 0,
"host" : "localhost:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
You can see priority: 1 and votes: 1
Non Voting Members:
- Non-voting members cannot participate in the election process and can't become a PRIMARY node and must have a priority of 0.
- Although non-voting members do not vote in elections, these members hold copies of the replica set’s data and can accept read operations from client applications.
They will have priority: 0 and votes: 0
Please refer to this link, on how different ways to configure SECONDARY nodes
Thank You…