The primary is the only member in the replica set that receives write operations. 主成员是副本集中唯一接收写操作的成员。MongoDB applies write operations on the primary and then records the operations on the primary's oplog. MongoDB在主数据库上应用写操作,然后在主数据库的oplog上记录操作。Secondary members replicate this log and apply the operations to their data sets.辅助成员复制此日志并将操作应用于其数据集。
In the following three-member replica set, the primary accepts all write operations. 在下面的三个成员副本集中,主副本接受所有写入操作。Then the secondaries replicate the oplog to apply to their data sets.然后,辅助服务器复制oplog以应用于其数据集。
All members of the replica set can accept read operations. 副本集的所有成员都可以接受读取操作。However, by default, an application directs its read operations to the primary member. 但是,默认情况下,应用程序将其读取操作定向到主成员。See Read Preference for details on changing the default read behavior.有关更改默认读取行为的详细信息,请参阅读取首选项。
The replica set can have at most one primary. 副本集最多可以有一个主副本。[1] If the current primary becomes unavailable, an election determines the new primary. 如果当前初选不可用,则选举将决定新的初选。See Replica Set Elections for more details.有关详细信息,请参阅复制集选择。
In the following 3-member replica set, the primary becomes unavailable. 在以下三成员副本集中,主副本不可用。This triggers an election which selects one of the remaining secondaries as the new primary.这将触发一次选举,从剩余的二级选举中选择一个作为新的初选。
[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 节点,并且对前一个primary 节点的新写入最终会回滚。 |