Docs HomeMongoDB Manual

Replica Set Secondary Members副本集辅助成员

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. 要复制数据,辅助进程会在异步进程中将操作从primary的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.辅助设备复制主设备的操作日志,并将操作应用于其数据集。

Diagram of a 3 member replica set that consists of a primary and two secondaries.

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.这会引发一场选举,剩下的一名中学生将成为新的小学生。

Diagram of an election of a new primary. In a three member replica set with two secondaries, the primary becomes unreachable. The loss of a primary triggers an election where one of the secondaries becomes the new primary

See Replica Set Elections for more details.有关详细信息,请参阅副本集选举

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.请参阅延迟的副本集成员
[1] Starting in version 4.2, secondary members of a replica set now log oplog entries that take longer than the slow operation threshold to apply. 从4.2版开始,副本集的辅助成员现在会记录应用时间超过慢速操作阈值的oplog条目These slow oplog messages:这些慢速操作日志消息:
  • Are logged for the secondaries in the diagnostic log.诊断日志中为辅助设备记录。
  • Are logged under the REPL component with the text applied op: <oplog entry> took <num>ms.REPL组件下记录,并应用文本applied op: <oplog entry> took <num>ms
  • Do not depend on the log levels (either at the system or component level)不依赖于日志级别(在系统或组件级别)
  • Do not depend on the profiling level.不要依赖于分析级别。
  • May be affected by slowOpSampleRate, depending on your MongoDB version:可能会受到slowOpSampleRate的影响,具体取决于您的MongoDB版本:
    • In MongoDB 4.2, these slow oplog entries are not affected by the slowOpSampleRate. MongoDB logs all slow oplog entries regardless of the sample rate.在MongoDB 4.2中,这些慢速操作日志条目不受slowOpSampleRate的影响。MongoDB记录所有慢速操作日志条目,而不管采样率如何。
    • In MongoDB 4.4 and later, these slow oplog entries are affected by the slowOpSampleRate.在MongoDB 4.4及更高版本中,这些慢速操作日志条目受到slowOpSampleRate的影响。
The profiler does not capture slow oplog entries.探查器未捕获慢速操作日志项。