Different Replica set members and states

Chandan Gr
4 min readJun 2, 2021

In this blog, we will discuss:
Different ways to configure Secondary members.
Different States in replica set members.

In replica sets .. as we know, there can be only 1 PRIMARY node and all the other nodes are considered as SECONDARY nodes. There are different ways to configure secondary nodes by changing priority, hidden, votes field values which are discussed below:

Different ways to configure Secondary members:

Priority 0 Replica Set Members:

rs.conf().members[x].votes = 1;
rs.conf().members[x].priority = 0;

  • They maintain a copy of the data set of the PRIMARY node, accept read operations.
  • These members can vote in elections.
  • These members cannot become a PRIMARY node.

Advantages:
It acts as a cold standby.

Hidden Replica Set Members:

rs.conf().members[x].votes = 1;
rs.conf().members[x].priority = 0;
rs.conf().members[x].hidden = true;

  • They maintain a copy of the data set of the PRIMARY node, and these nodes will be hidden.
  • These members can vote in elections.
  • Hidden members must always be priority 0 members and so cannot become primary.
  • Since these members are hidden, clients cannot perform read operations on them.

Advantages:
Hidden members for dedicated tasks such as reporting and backups.

Delayed Replica Set Members:

rs.conf().members[x].votes = 1;
rs.conf().members[x].priority = 0;
rs.conf().members[x].hidden = true;
rs.conf().members[x].slaveDelay = 3600;

  • They maintain a copy of the data set of the PRIMARY node, delayed member’s data set reflects an earlier, or delayed, state of the set.
    For example, if the current time is 10 pm and a delayed member has a delay of 1hr, then the delayed member will have operations till 9 pm. So it contains data set of PRIMARY node till 9 pm.
  • Delayed members copy and apply operations from the source oplog on a delay time specified.
  • These members can vote in elections.
  • Delayed members must always be priority 0 members and hidden members, so they cannot become a PRIMARY node.
  • Since these members are hidden, clients cannot perform read operations on them.

Advantages:
Because delayed members are a rolling backup or a running historical snapshot of the data set, they may help you recover from various kinds of human error.
For example, delayed members are similar to git, which can be reverted to previous backup snapshots, in case of unsuccessful application upgrades or operational errors.

Different States in replica members:

rs0 is in secondary state

Replica set members can be present in different states, we can see their state in the cmd.
In the above picture, the replica set is in a SECONDARY state. Let's discuss all the different states present:

STARTUP state: Not yet an active member of any set. All members start-up in this state.

PRIMARY state: The member in state primary is the only member that can accept write operations.
rs.conf().members[x].priority = 1;

SECONDARY state: A member in state secondary is replicating the data store. They are eligible to vote.

RECOVERING state:

  • Due to overload, a Secondary may fall far enough behind the other members of the replica set. It may need to resync with the rest of the set. When this happens, the member enters the RECOVERING state and requires manual intervention.
  • When the member is in RECOVERING state, it does not take read operations, it cannot become PRIMARY but are eligible for voting in elections.

STARTUP2 state:

  • Each data-bearing member of a replica set enters the STARTUP2 state as soon as mongod finishes loading that member's configuration
  • The member then decides whether or not to undertake initial sync. If a member begins initial sync, the member remains in STARTUP2 until all data is copied and all indexes are built.

UNKNOWN state:
Members that have never communicated, are said to be in an UNKNOWN state.

ARBITER state:

  • Members in the ARBITER state do not replicate data from the PRIMARY node or accept write operations.
  • They are eligible to vote and exist solely to break a tie during elections. Replica sets should only 1 member in the ARBITER state if the replica set has an even number of voting members.

DOWN: If the member is not reachable to others, then it will be in a DOWN state.

ROLLBACK: If the delayed replica set member is performing a rollback, then it will be in a ROLLBACK state.

REMOVED: This member was once in a replica set but was subsequently removed.

Thank You…

--

--