Replica Set Member States副本集成员状态
Each member of a replica set has a state.副本集的每个成员都有一个状态。
| 0 | STARTUP | mongod parses the replica set configuration document while in STARTUP.mongod在STARTUP中解析副本集配置文档。 |
| 1 | PRIMARY | |
| 2 | SECONDARY | |
| 3 | RECOVERING | |
| 5 | STARTUP2 | |
| 6 | UNKNOWN | |
| 7 | ARBITER | |
| 8 | DOWN | |
| 9 | ROLLBACK | ROLLBACK state. ROLLBACK状态时,MongoDB会终止所有正在进行的用户操作。 |
| 10 | REMOVED |
States状态
Core States核心状态
PRIMARY-
Members in处于PRIMARYstate accept write operations.PRIMARY状态的成员接受写操作。A replica set has at most one primary at a time.复制副本集一次最多有一个主副本。[1]ASECONDARYmember becomes primary after an election.SECONDARY成员在选举后成为主要成员。Members in thePRIMARYstate are eligible to vote.PRIMARY状态的成员有资格投票。
SECONDARY-
Members in处于SECONDARYstate 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 thesecondary有资格在选举中投票,如果primary变成不可用,他们可以被选入PRIMARYstate if the primary becomes unavailable.PRIMARY状态。
ARBITER-
Members in处于ARBITERstate 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如果副本集的投票成员数为偶数,并且可能会遭遇平局选举,那么副本集应该只有一个处于ARBITERstate 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复制副本集的每个成员都以STARTUPstate.STARTUP状态启动。mongodthen loads that member's replica set configuration, and transitions the member's state toSTARTUP2orARBITER.mongod然后加载该成员的副本集配置,并将该成员的状态转换为STARTUP2或ARBITER。Members inSTARTUPare not eligible to vote, as they are not yet a recognized member of any replica set.STARTUP中的成员没有资格投票,因为他们还不是任何副本集的公认成员。
STARTUP2Changed in version 5.0.5.0版更改。Each data-bearing member of a replica set enters the一旦STARTUP2state as soon asmongodfinishes loading that member's configuration.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如果某个成员开始初始同步,则该成员将保留在STARTUP2until all data is copied and all indexes are built.STARTUP2中,直到复制了所有数据并建立了所有索引。Afterwards, the member transitions to然后,成员转换到RECOVERING.RECOVERING。Newly-added members inSTARTUP2are not eligible to vote and cannot be elected during the initial sync process.STARTUP2中新添加的成员没有资格投票,并且在初始同步过程中无法当选。Prior to MongoDB 5.0, members in在MongoDB 5.0之前,STARTUP2were eligible to vote.STARTUP2中的成员有资格投票。
RECOVERING-
A member of a replica set enters副本集的成员在未准备好接受读取时进入RECOVERINGstate when it is not ready to accept reads.RECOVERING状态。TheRECOVERINGstate can occur during normal operation, and doesn't necessarily reflect an error condition.RECOVERING状态可能发生在正常操作期间,并不一定反映错误情况。Members in theRECOVERINGstate are eligible to vote in elections, but are not eligible to enter thePRIMARYstate.RECOVERING状态的成员有资格在选举中投票,但没有资格进入PRIMARY状态。A member transitions from在复制足够的数据以保证客户端读取数据的一致性后,成员从RECOVERINGtoSECONDARYafter replicating enough data to guarantee a consistent view of the data for client reads.RECOVERING转换为SECONDARY。The only difference betweenRECOVERINGandSECONDARYstates is thatRECOVERINGprohibits client reads andSECONDARYpermits them.RECOVERING和SECONDARY状态之间的唯一区别是,RECOVERING禁止客户端读取,SECONDARY允许客户端读取。SECONDARYstate does not guarantee anything about the staleness of the data with respect to the primary.state并不保证数据相对于主数据的陈旧性。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发生这种情况时,成员将进入RECOVERINGstate 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时,旧的主成员可能包含未复制到secondary成员的文档。In this case, the old primary member reverts those writes. During rollback, the member will have在这种情况下,旧的主要成员会恢复这些写入。在回滚期间,成员将处于ROLLBACKstate.ROLLBACK状态。Members in theROLLBACKstate are eligible to vote in elections.ROLLBACK状态的成员有资格在选举中投票。Starting in version 4.2, MongoDB kills all in-progress user operations when a member enters the从4.2版本开始,当成员进入ROLLBACKstate.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从未向副本集传递过状态信息的成员处于UNKNOWNstate.UNKNOWN状态。
DOWN-
Members that lose their connection to the replica set are seen as丢失与副本集连接的成员会被副本集的其余成员视为DOWNby the remaining members of the set.DOWN。
REMOVED-
Members that are removed from the replica set enter the从副本集中删除的成员将进入REMOVEDstate.REMOVED状态。When members enter the当成员进入REMOVEDstate, the logs will mark this event with areplSet REMOVEDmessage entry.REMOVED状态时,日志将使用replSet REMOVED消息条目标记此事件。
| [1] | { w: "majority" } write concern. { w: "majority" }写入关注的写入。{ 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" }写入的节点是当前主节点,而另一个节点是尚未识别其降级的前主节点,通常是由于网络分区。primary, and new writes to the former primary will eventually roll back.primary,并且对前一个primary的新写入最终会回滚。 |