Replica Set Member States
Each member of a replica set has a state.
Number | Name | State Description |
---|---|---|
0 | STARTUP | Not yet an active member of any set. All members start up inthis state. The mongod parses the replica setconfiguration document while inSTARTUP . |
1 | PRIMARY | The member in state primaryis the only member that can accept write operations. Eligible tovote. |
2 | SECONDARY | A member in state secondaryis replicating the data store. Eligible to vote. |
3 | RECOVERING | Members either perform startup self-checks, or transition fromcompleting a rollback orresync. Eligible tovote. |
5 | STARTUP2 | The member has joined the set and is running an initial sync. Eligible tovote. |
6 | UNKNOWN | The member’s state, as seen from another member of the set, is not yet known. |
7 | ARBITER | Arbiters do not replicate data and exist solely to participate in elections. Eligible to vote. |
8 | DOWN | The member, as seen from another member of the set, is unreachable. |
9 | ROLLBACK | This 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. |
10 | REMOVED | This 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] ASECONDARY
member becomes primaryafter an election. Members in thePRIMARY
state 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 thePRIMARY
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 theARBITER
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
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, as they are not yet a recognized member of any replica set.
STARTUP2
- Each member of a replica set enters the
STARTUP2
state assoon asmongod
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 inSTARTUP2
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. TheRECOVERING
statecan occur during normal operation, and doesn’t necessarily reflectan error condition. Members in theRECOVERING
stateare eligible to vote in elections, but are not eligible to enter thePRIMARY
state.
A member transitions from RECOVERING
to SECONDARY
after replicating enough data to guarantee a consistent view of the data forclient reads. The only difference between RECOVERING
and SECONDARY
states is that RECOVERING
prohibits 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 have
ROLLBACK
state. Members in theROLLBACK
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
REMOVED
state.When members enter theREMOVED
state, the logs willmark this event with areplSet 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. |