Replica Set Member States副本集成员状态

Each member of a replica set has a state.副本集的每个成员都有一个状态。

NumberName名称State Description状态描述
0STARTUPNot yet an active member of any set. 尚未成为任何集合的活动成员。All members start up in this state. 所有成员都在该状态启动。The mongod parses the replica set configuration document while in STARTUP.mongodSTARTUP时解析副本集配置文档
1PRIMARYThe member in state primary is the only member that can accept write operations. primary状态中的成员是唯一可以接受写操作的成员。Eligible to vote.有资格投票。
2SECONDARYA member in state secondary is replicating the data store. 状态为secondary的成员正在复制数据存储。Eligible to vote.有资格投票。
3RECOVERINGMembers either perform startup self-checks, or transition from completing a rollback or resync. 成员可以执行启动自检,或者从完成回滚重新同步过渡。Data is not available for reads from this member. 无法从该成员读取数据。Eligible to vote.有资格投票。
5STARTUP2

The member has joined the set and is running an initial sync. 成员已加入集合并正在运行初始同步。Eligible to vote.有资格投票。

Note注意

Starting in MongoDB 5.0, if the member was newly added to the replica set, it is not eligible to vote and cannot be elected during the initial sync process.从MongoDB 5.0开始,如果成员是新添加到副本集的,则该成员没有投票资格,在初始同步过程中无法当选。

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.从集合的另一个成员看到的成员是不可访问的。
9ROLLBACK

This member is actively performing a rollback. 此成员正在积极执行回滚Eligible to vote. 有资格投票。Data is not available for reads from this member.无法从该成员读取数据。

Starting in version 4.2, MongoDB kills all in-progress user operations when a member enters the ROLLBACK state.从4.2版开始,当成员进入ROLLBACK状态时,MongoDB会终止所有正在进行的用户操作。

10REMOVEDThis member was once in a replica set but was subsequently removed.此成员曾经位于副本集中,但随后被删除。

States状态

Core States核心状态

PRIMARY

Members in PRIMARY state accept write operations. 处于PRIMARY状态的成员接受写操作。A replica set has at most one primary at a time. 副本集一次最多有一个主副本。[1] A SECONDARY member becomes primary after an election. SECONDARY成员在选举后成为primary。Members in the PRIMARY state are eligible to vote.PRIMARY状态的成员有资格投票。

SECONDARY

Members in SECONDARY state replicate the primary's data set and can be configured to accept read operations. 处于SECONDARY状态的成员复制主数据集,并且可以配置为接受读取操作。Secondaries are eligible to vote in elections, and may be elected to the PRIMARY state if the primary becomes unavailable.secondary有资格在选举中投票,如果初选无法进行,则可以当选为PRIMARY状态。

ARBITER

Members in ARBITER state do not replicate data or accept write operations. 处于ARBITER状态的成员不复制数据或接受写操作。They are eligible to vote, and exist solely to break a tie during elections. 他们有资格投票,他们的存在只是为了在选举中打破僵局。Replica sets should only have a member in the ARBITER state if the set would otherwise have an even number of voting members, and could suffer from tied elections. 如果复制集只有偶数个有投票权的成员,并且可能遭受平局选举,则复制集只能有一个成员处于ARBITER状态。There should only be at most one arbiter configured in any replica set. 任何副本集中最多只能配置一个仲裁器。For considerations when using an arbiter, see Replica Set Arbiter.有关使用仲裁器时的注意事项,请参阅副本集仲裁器

See Replica Set Members for more information on core states.有关核心状态的更多信息,请参阅副本集成员

Other States其他状态

STARTUP

Each member of a replica set starts up in STARTUP state. 副本集的每个成员都以STARTUP状态启动。mongod then loads that member's replica set configuration, and transitions the member's state to STARTUP2 or ARBITER. mongod然后加载该成员的副本集配置,并将该成员的状态转换为STARTUP2ARBITERMembers in STARTUP are not eligible to vote, as they are not yet a recognized member of any replica set.STARTUP中的成员没有资格投票,因为他们还不是任何副本集的公认成员。

STARTUP2

Each data-bearing member of a replica set enters the STARTUP2 state as soon as mongod finishes loading that member's configuration, at which time it becomes an active member of the replica set and is eligible to vote.复制集的每个数据承载成员在mongod完成加载该成员的配置后,立即进入STARTUP2状态,此时它将成为复制集的活动成员并有资格投票。

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 all data is copied and all indexes are built. 如果成员开始初始同步,则该成员将保留在STARTUP2中,直到复制所有数据并构建所有索引。Afterwards, the member transitions to RECOVERING.然后,成员转换到RECOVERING

Note注意

Starting in MongoDB 5.0, if the member was newly added to the replica set, it is not eligible to vote and cannot be elected during the initial sync process.从MongoDB 5.0开始,如果成员是新添加到副本集的,则该成员没有投票资格,在初始同步过程中无法当选。

RECOVERING

A member of a replica set enters RECOVERING state when it is not ready to accept reads. 副本集的成员在未准备好接受读取时进入RECOVERING状态。The RECOVERING state can occur during normal operation, and doesn't necessarily reflect an error condition. RECOVERING状态可能发生在正常操作期间,并不一定反映错误情况。Members in the RECOVERING state are eligible to vote in elections, but are not eligible to enter the PRIMARY state.RECOVERING状态的成员有资格在选举中投票,但没有资格进入PRIMARY状态。

A member transitions from RECOVERING to SECONDARY after replicating enough data to guarantee a consistent view of the data for client reads. 复制足够的数据以确保客户端读取的数据视图一致后,成员从RECOVERING转换到SECONDARYThe only difference between RECOVERING and SECONDARY states is that RECOVERING prohibits client reads and SECONDARY permits them. RECOVERINGSECONDARY状态之间的唯一区别是RECOVERING禁止客户端读取,SECONDARY允许客户端读取。SECONDARY state 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. 由于过载,secondary可能远远落后于副本集的其他成员,因此可能需要与副本集的其余成员重新同步When this happens, the member enters the RECOVERING state and requires manual intervention.发生这种情况时,成员将进入RECOVERING状态,需要手动干预。

ROLLBACK

Whenever the replica set replaces a primary in an election, the old primary may contain documents that did not replicate to the secondary members. 每当副本集在选举中替换primary时,旧的primary可能包含未复制到secondary成员的文档。In this case, the old primary member reverts those writes. 在这种情况下,旧的主要成员将恢复这些写入。During rollback, the member will have ROLLBACK state. 回滚期间,成员将处于ROLLBACK状态。Members in the ROLLBACK state are eligible to vote in elections.ROLLBACK状态的成员有资格在选举中投票。

Starting in version 4.2, MongoDB kills all in-progress user operations when a member enters the ROLLBACK state.从4.2版开始,当成员进入ROLLBACK状态时,MongoDB会终止所有正在进行的用户操作。

Error States错误状态

Members in any error state can't vote.处于任何错误状态的成员都不能投票。

UNKNOWN

Members that have never communicated status information to the replica set are in the UNKNOWN state.从未向副本集传递状态信息的成员处于UNKNOWN状态。

DOWN

Members that lose their connection to the replica set are seen as DOWN by the remaining members of the set.失去与副本集连接的成员被该集的其余成员视为DOWN

REMOVED

Members that are removed from the replica set enter the REMOVED state. 从副本集中删除的成员将进入REMOVED状态。When members enter the REMOVED state, the logs will mark this event with a replSet REMOVED message entry.当成员进入REMOVED状态时,日志将用replSet REMOVED消息条目标记此事件。

[1] In some circumstances, two nodes in a replica set may transiently believe that they are the primary, but at most, one of them will be able to complete writes with { w: "majority" } write concern. 某些情况下,副本集中的两个节点可能会暂时认为自己是主节点,但最多只有一个节点能够完成写操作,而不必担心{ w: "majority" }写操作。The node that can complete { w: "majority" } writes is the current primary, and the other node is a former primary that has not yet recognized its demotion, typically due to a network partition. 可以完成{ w: "majority" }写入的节点是当前主节点,而另一个节点是尚未识别其降级的前主节点,通常是由于网络分区When this occurs, clients that connect to the former primary may observe stale data despite having requested read preference primary, and new writes to the former primary will eventually roll back.发生这种情况时,连接到前一个主服务器的客户端可能会观察到过时的数据,尽管请求了读取首选项primary,但对前一个主机的新写入最终会回滚。
←  The local DatabaseSharding →