Replica Set Member States

Each member of a replica set has a state.

NumberNameState Description
0STARTUPNot yet an active member of any set. All members start up inthis state. The mongod parses the replica setconfiguration document while inSTARTUP.
1PRIMARYThe member in state primaryis the only member that can accept write operations. Eligible tovote.
2SECONDARYA member in state secondaryis replicating the data store. Eligible to vote.
3RECOVERINGMembers either perform startup self-checks, or transition fromcompleting a rollback orresync. Eligible tovote.
5STARTUP2The member has joined the set and is running an initial sync. Eligible tovote.
6UNKNOWNThe member’s state, as seen from another member of the set, is not yet known.
7ARBITERArbiters do not replicate data and exist solely to participate in elections. Eligible to vote.
8DOWNThe member, as seen from another member of the set, is unreachable.
9ROLLBACKThis member is actively performing a rollback. Eligible tovote. Data is not available for reads from this member.Starting in version 4.2, MongoDB kills all in-progress useroperations when a member enters the ROLLBACK state.
10REMOVEDThis member was once in a replica set but was subsequently removed.

States

Core States

  • PRIMARY
  • Members in PRIMARY state accept write operations. A replica set has at mostone primary at a time. [1] A SECONDARY member becomes primaryafter an election. Members in the PRIMARYstate are eligible to vote.
  • SECONDARY
  • Members in SECONDARY state replicate the primary’s data setand can be configured to accept read operations. Secondaries are eligible to vote inelections, and may be elected to the PRIMARY state if theprimary becomes unavailable.
  • ARBITER
  • Members in ARBITER state do not replicate data or accept write operations.They are eligible to vote, and exist solely to break a tie duringelections. Replica sets should only have a member in the ARBITER stateif the set would otherwise have an even number of members, and could sufferfrom tied elections. There should only be at most one arbiter configuredin any replica set.

See Replica Set Members for more information on core states.

Other States

  • STARTUP
  • Each member of a replica set starts up in STARTUPstate. mongod then loads that member’s replica set configuration,and transitions the member’s state to STARTUP2. Members inSTARTUP are not eligible to vote, as they are not yet a recognized member of any replica set.
  • STARTUP2
  • Each member of a replica set enters the STARTUP2 state assoon as mongod finishes loading that member’sconfiguration, at which time it becomes an active member of the replica set and is eligible to vote.The member then decides whether or not to undertake an initial sync.If a member begins an initial sync, the member remains in STARTUP2 until alldata is copied and all indexes are built. Afterwards, the member transitions toRECOVERING.
  • RECOVERING
  • A member of a replica set enters RECOVERING state whenit is not ready to accept reads. The RECOVERING statecan occur during normal operation, and doesn’t necessarily reflectan error condition. Members in the RECOVERING stateare eligible to vote in elections, but are not eligible to enter thePRIMARY state.

A member transitions from RECOVERING to SECONDARYafter replicating enough data to guarantee a consistent view of the data forclient reads. The only difference between RECOVERINGand SECONDARY states is that RECOVERINGprohibits client reads and SECONDARY permits them.SECONDARY state does not guarantee anything about thestaleness of the data with respect to the primary.

Due to overload, a secondary may fall far enough behind theother members of the replica set such that it may need to resync with therest of the set. When this happens, the member enters theRECOVERING state and requires manual intervention.

  • ROLLBACK
  • Whenever the replica set replaces a primary in anelection, the old primary may contain documentsthat did not replicate to the secondarymembers. In this case, the old primary member reverts those writes. Duringrollback, the member will haveROLLBACK state. Members in the ROLLBACK stateare eligible to vote in elections.

Starting in version 4.2, MongoDB kills all in-progress useroperations when a member enters the ROLLBACK state.

Error States

Members in any error state can’t vote.

  • UNKNOWN
  • Members that have never communicated status information to the replicaset are in the UNKNOWN state.
  • DOWN
  • Members that lose their connection to the replica set are seen as DOWN by the remaining members of the set.
  • REMOVED
  • Members that are removed from the replica set enter the REMOVEDstate.When members enter the REMOVED state, the logs willmark this event with a replSet REMOVED message entry.
[1]In some circumstances, two nodes in a replica setmay transiently believe that they are the primary, but at most, oneof them will be able to complete writes with { w:"majority" } write concern. The node that can complete{ w: "majority" } writes is the currentprimary, and the other node is a former primary that has not yetrecognized its demotion, typically due to a network partition.When this occurs, clients that connect to the former primary mayobserve stale data despite having requested read preferenceprimary, and new writes to the former primary willeventually roll back.