A secondary maintains a copy of the primary's data set. 辅助服务器维护primary服务器数据集的副本。To replicate data, a secondary applies operations from the primary's oplog to its own data set in an asynchronous process. 为了复制数据,辅助服务器在异步进程中将主服务器oplog中的操作应用于其自己的数据集。[1]A replica set can have one or more secondaries.副本集可以有一个或多个辅助副本。
The following three-member replica set has two secondary members. 以下三成员副本集有两个辅助成员。The secondaries replicate the primary's oplog and apply the operations to their data sets.辅助服务器复制主服务器的oplog,并将操作应用于其数据集。
Although clients cannot write data to secondaries, clients can read data from secondary members. 尽管客户端无法将数据写入辅助成员,但客户端可以从辅助成员读取数据。See Read Preference for more information on how clients direct read operations to replica sets.有关客户端如何将读取操作定向到副本集的更多信息,请参阅读取首选项。
A secondary can become a primary. 次级可以成为初级。If the current primary becomes unavailable, the replica set holds an election to choose which of the secondaries becomes the new primary.如果当前主副本不可用,则复制集将进行选举,以选择哪个辅助副本成为新的主副本。
In the following three-member replica set, the primary becomes unavailable. 在以下三个成员副本集中,主副本不可用。This triggers an election where one of the remaining secondaries becomes the new primary.这引发了一场选举,剩余的二级候选人之一成为新的初选。
You can configure a secondary member for a specific purpose. 您可以为特定目的配置辅助成员。You can configure a secondary to:您可以将辅助配置为:
Prevent it from becoming a primary in an election, which allows it to reside in a secondary data center or to serve as a cold standby. 防止它在选举中成为主数据中心,这允许它驻留在辅助数据中心或作为冷备用。See Priority 0 Replica Set Members.请参见优先级0副本集成员。
Prevent applications from reading from it, which allows it to run applications that require separation from normal traffic. 防止应用程序从中读取,这允许它运行需要与正常通信分离的应用程序。See Hidden Replica Set Members.请参见隐藏副本集成员。
Keep a running "historical" snapshot for use in recovery from certain errors, such as unintentionally deleted databases. 保留一个正在运行的“历史”快照,以用于从某些错误(如意外删除的数据库)中恢复。See Delayed Replica Set Members.请参见延迟副本集成员。
Starting in version 4.2 (also available starting in 4.0.6), secondary members of a replica set now log oplog entries that take longer than the slow operation threshold to apply. 从4.2版开始(从4.0.6版开始也可用),副本集的辅助成员现在记录的oplog条目比应用慢操作阈值所需的时间更长。These slow oplog messages:这些慢oplog消息:
In MongoDB 4.2 and earlier, these slow oplog entries are not affected by the slowOpSampleRate. 在MongoDB 4.2及更早版本中,这些慢oplog条目不受slowOpSampleRate的影响。MongoDB logs all slow oplog entries regardless of the sample rate.无论采样率如何,MongoDB都会记录所有慢操作日志条目。
In MongoDB 4.4 and later, these slow oplog entries are affected by the slowOpSampleRate.在MongoDB 4.4及更高版本中,这些慢oplog条目受slowOpSampleRate的影响。
The profiler does not capture slow oplog entries.探查器不捕获慢oplog条目。