- 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
PRIMARY
state accept write operations. A replica set has only one primary at a time. ASECONDARY
member becomes primary after an election. Members in thePRIMARY
state are eligible to vote.
-
SECONDARY
¶ Members in
SECONDARY
state 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 thePRIMARY
state if the primary 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 during elections. Replica sets should only have a member in theARBITER
state 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
STARTUP
state.mongod
then loads that member’s replica set configuration, and transitions the member’s state toSTARTUP2
. Members inSTARTUP
are not eligible to vote.
-
STARTUP2
¶ Each member of a replica set enters the
STARTUP2
state as soon asmongod
finishes loading that member’s configuration. While in theSTARTUP2
state, the member creates threads to handle internal replication operations. Members are in theSTARTUP2
state for a short period of time before entering theRECOVERING
state. Members in theSTARTUP2
state are not eligible to vote.
-
RECOVERING
¶ A member of a replica set enters
RECOVERING
state when it is not ready to accept reads. TheRECOVERING
state can occur during normal operation, and doesn’t necessarily reflect an error condition. Members in theRECOVERING
state are eligible to vote in elections, but is not eligible to enter thePRIMARY
state.During startup, members transition through
RECOVERING
afterSTARTUP2
and 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
RECOVERING
state.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
RECOVERING
state.On secondaries, the
compact
andreplSetMaintenance
commands force the secondary to enterRECOVERING
state. 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
FATAL
state. Members in this state requires administrator intervention.
-
UNKNOWN
¶ Members that have never communicated status information to the replica set are in the
UNKNOWN
state.
-
REMOVED
¶ Members that are removed from the replica set enter the
REMOVED
state. When members enter theREMOVED
state, the logs will mark this event with areplSet REMOVED
message entry.
-
ROLLBACK
¶ When a
SECONDARY
rolls back a write operation after transitioning fromPRIMARY
, it enters theROLLBACK
state. See Rollbacks During Replica Set Failover.