副本集的每个成员都有一个状态。
数值 | 名称 | 状态描述 |
|---|---|---|
0 | Not yet an active member of any set. All members start up in this state. The | |
1 | 处于主节点状态的成员是唯一可以接受写入操作的成员。有资格投票。 | |
2 | 处于从节点状态的成员正在复制数据存储。有资格投票。 | |
3 | ||
5 | 节点正在运行初始同步。有资格投票,但新添加到副本集时除外。 | |
6 | 从集合中的另一个成员来看,该成员的状态尚不清楚。 | |
7 | 仲裁节点不复制数据,其存在的唯一目的是参与选举。有资格投票。 | |
8 | 从集合的另一个成员来看,该成员是无法访问的。 | |
9 | ||
10 | 此成员曾经在副本集中,但随后被删除。 |
状态
核心状态
PRIMARYMembers in
PRIMARYstate accept write operations. A replica set has at most one primary at a time. [1] ASECONDARYmember becomes primary after an election. Members in thePRIMARYstate are eligible to vote.
SECONDARYMembers 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.
ARBITERMembers 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 voting members, and could suffer from tied elections. There should only be at most one arbiter configured in any replica set. For considerations when using an arbiter, see Replica Set Arbiter.
有关核心状态的详细信息,请参阅副本集成员。
其他状态
STARTUPEach member of a replica set starts up in
STARTUPstate.mongodthen loads that member's replica set configuration, and transitions the member's state toSTARTUP2orARBITER. Members inSTARTUPare not eligible to vote, as they are not yet a recognized member of any replica set.
STARTUP2在版本5.0中进行了更改。
Each data-bearing member of a replica set enters the
STARTUP2state as soon asmongodfinishes loading that member's configuration.The member then decides whether or not to undertake an initial sync. If a member begins an initial sync, the member remains in
STARTUP2until all data is copied and all indexes are built. Afterwards, the member transitions toRECOVERING.Newly-added members in
STARTUP2are not eligible to vote and cannot be elected during the initial sync process. Prior to MongoDB 5.0, members inSTARTUP2were eligible to vote.
RECOVERINGA 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 are not eligible to enter thePRIMARYstate.A member transitions from
RECOVERINGtoSECONDARYafter replicating enough data to guarantee a consistent view of the data for client reads. The only difference betweenRECOVERINGandSECONDARYstates is thatRECOVERINGprohibits client reads andSECONDARYpermits them.SECONDARYstate does not guarantee anything about the staleness of the data with respect to the primary.Due to overload, a secondary may fall far enough behind the other members of the replica set such that it may need to resync with the rest of the set. When this happens, the member enters the
RECOVERINGstate and requires manual intervention.
ROLLBACKWhenever the replica set replaces a primary in an election, the old primary may contain documents that did not replicate to the secondary members. In this case, the old primary member reverts those writes. During rollback, the member will have
ROLLBACKstate. Members in theROLLBACKstate are eligible to vote in elections.Starting in version 4.2, MongoDB kills all in-progress user operations when a member enters the
ROLLBACKstate.
错误状态
处于任何错误状态的成员都不能投票。
UNKNOWNMembers that have never communicated status information to the replica set are in the
UNKNOWNstate.
DOWNMembers that lose their connection to the replica set are seen as
DOWNby the remaining members of the set.
REMOVEDMembers that are removed from the replica set enter the
REMOVEDstate. When members enter theREMOVEDstate, the logs will mark this event with areplSet REMOVEDmessage entry.
| [1] | 在某些情况下,副本集中的两个节点可能会暂时认为它们是主节点,但最多只能有其中一个节点能够完成具有 |