Docs HomeMongoDB Manual

Manage Chained Replication管理链式复制

Starting in version 2.0, MongoDB supports chained replication. A chained replication occurs when a secondary member replicates from another secondary member instead of from the primary. 从2.0版本开始,MongoDB支持链式复制。当辅助成员从另一个secondary成员而不是从primary进行复制时,就会发生链式复制。This might be the case, for example, if a secondary selects its replication target based on ping time and if the closest member is another secondary.例如,如果辅助设备根据ping时间选择其复制目标,并且最近的成员是另一个辅助设备,则可能会出现这种情况。

Chained replication can reduce load on the primary. 链式复制可以减少主服务器上的负载。But chained replication can also result in increased replication lag, depending on the topology of the network.但是链式复制也会导致复制滞后增加,这取决于网络的拓扑结构。

You can use the settings.chainingAllowed setting in Replica Set Configuration to disable chained replication for situations where chained replication is causing lag.在链式复制导致滞后的情况下,可以使用副本集配置中的settings.chainingAllowed设置禁用链式复制。

MongoDB enables chained replication by default. MongoDB默认启用链式复制。This procedure describes how to disable it and how to re-enable it.此过程描述了如何禁用它以及如何重新启用它。

Note

If chained replication is disabled, you still can use replSetSyncFrom to specify that a secondary replicates from another secondary. 如果禁用了链式复制,您仍然可以使用replSetSyncFrom指定从另一个辅助进行复制。But that configuration will last only until the secondary recalculates which member to sync from.但这种配置只会持续到次要成员重新计算要从哪个成员同步为止。

Disable Chained Replication禁用链式复制

To disable chained replication, set the settings.chainingAllowed field in Replica Set Configuration to false.要禁用链式复制,请将副本集配置中的settings.chainingAllowed字段设置为false

You can use the following sequence of commands to set settings.chainingAllowed to false:您可以使用以下命令序列将settings.chainingAllowed设置为false

  1. Copy the configuration settings into the cfg object:将配置设置复制到cfg对象中:

    cfg = rs.config()
  2. Take note of whether the current configuration settings contain the settings embedded document. 请注意当前配置settings是否包含嵌入文档的设置。If they do, skip this step.如果是,请跳过此步骤。

    Warning

    To avoid data loss, skip this step if the configuration settings contain the settings embedded document.为避免数据丢失,如果配置设置包含嵌入文档的settings,请跳过此步骤。

    If the current configuration settings do not contain the settings embedded document, create the embedded document by issuing the following command:如果当前配置设置不包含嵌入文档的settings,请通过发出以下命令创建嵌入文档:

    cfg.settings = { }
  3. Issue the following sequence of commands to set settings.chainingAllowed to false:发出以下命令序列,将settings.chainingAllowed设置为false

    cfg.settings.chainingAllowed = false
    rs.reconfig(cfg)

Re-enable Chained Replication重新启用链式复制

To re-enable chained replication, set settings.chainingAllowed to true. You can use the following sequence of commands:若要重新启用链式复制,请将settings.chainingAllowed设置为true。您可以使用以下命令序列:

cfg = rs.config()
cfg.settings.chainingAllowed = true
rs.reconfig(cfg)