- Replication >
- Replication Reference >
- Replica Set Member States
Replica Set Member States¶
On this page
Members of replica sets have states that reflect the startup process, basic operations, and potential error states.
| Number | Name | State Description |
|---|---|---|
| 0 | STARTUP |
Cannot vote. All members start up in this state. The
mongod parses the replica set configuration document while in STARTUP. |
| 1 | PRIMARY |
Can vote. The primary is the only member to accept write operations. |
| 2 | SECONDARY |
Can vote. The secondary replicates the data store. |
| 3 | RECOVERING |
Can vote. Members either perform startup self-checks, or transition from completing a rollback or resync. |
| 4 | FATAL |
Cannot vote. Has encountered an unrecoverable error. |
| 5 | STARTUP2 |
Cannot vote. Forks replication and election threads before becoming a secondary. |
| 6 | UNKNOWN |
Cannot vote. Has never connected to the replica set. |
| 7 | ARBITER |
Can vote. Arbiters do not replicate data and exist solely to participate in elections. |
| 8 | DOWN |
Cannot vote. Is not accessible to the set. |
| 9 | ROLLBACK |
Can vote. Performs a rollback. |
| 10 | REMOVED |
Cannot vote. Was once in the replica set but has now been removed. |
States¶
Core States¶
-
PRIMARY¶ Members in
PRIMARYstate accept write operations. A replica set has only one primary at a time. ASECONDARYmember becomes primary after an election. Members in thePRIMARYstate are eligible to vote.
-
SECONDARY¶ Members in
SECONDARYstate replicate the primary’s data set and can be configured to accept read operations. Secondaries are eligible to vote in elections, and may be elected to thePRIMARYstate if the primary becomes unavailable.
-
ARBITER¶ Members in
ARBITERstate do not replicate data or accept write operations. They are eligible to vote, and exist solely to break a tie during elections. Replica sets should only have a member in theARBITERstate if the set would otherwise have an even number of members, and could suffer from tied elections. Like primaries, there should only be at most one arbiter in any replica set.
See Replica Set Members for more information on core states.
Initialization States¶
-
STARTUP¶ Each member of a replica set starts up in
STARTUPstate.mongodthen loads that member’s replica set configuration, and transitions the member’s state toSTARTUP2. Members inSTARTUPare not eligible to vote.
-
STARTUP2¶ Each member of a replica set enters the
STARTUP2state as soon asmongodfinishes loading that member’s configuration. While in theSTARTUP2state, the member creates threads to handle internal replication operations. Members are in theSTARTUP2state for a short period of time before entering theRECOVERINGstate. Members in theSTARTUP2state are not eligible to vote.
-
RECOVERING¶ A member of a replica set enters
RECOVERINGstate when it is not ready to accept reads. TheRECOVERINGstate can occur during normal operation, and doesn’t necessarily reflect an error condition. Members in theRECOVERINGstate are eligible to vote in elections, but is not eligible to enter thePRIMARYstate.During startup, members transition through
RECOVERINGafterSTARTUP2and before becomingSECONDARY.During normal operation, if a secondary falls behind the other members of the replica set, it may need to resync with the rest of the set. While resyncing, the member enters the
RECOVERINGstate.Whenever the replica set replaces a primary in an election, the old primary’s data collection may contain documents that did not have time to replicate to the secondary members. In this case the member rolls back those writes. During rollback, the member will have
RECOVERINGstate.On secondaries, the
compactandreplSetMaintenancecommands force the secondary to enterRECOVERINGstate. This prevents clients from reading during those operations.
Error States¶
Members in any error state can’t vote.
-
FATAL¶ Members that encounter an unrecoverable error enter the
FATALstate. Members in this state requires administrator intervention.
-
UNKNOWN¶ Members that have never communicated status information to the replica set are in the
UNKNOWNstate.
-
REMOVED¶ Members that are removed from the replica set enter the
REMOVEDstate. When members enter theREMOVEDstate, the logs will mark this event with areplSet REMOVEDmessage entry.
-
ROLLBACK¶ When a
SECONDARYrolls back a write operation after transitioning fromPRIMARY, it enters theROLLBACKstate. See Rollbacks During Replica Set Failover.