Manage Chained Replication管理链接复制

On this page本页内容

Starting in version 2.0, MongoDB supports chained replication. 从2.0版开始,MongoDB支持链式复制。A chained replication occurs when a secondary member replicates from another secondary member instead of from the primary. 当辅助成员从另一个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. 要重新启用链式复制,请将settings.chainingAllowed设置为trueYou can use the following sequence of commands:可以使用以下命令序列:

cfg = rs.config()
cfg.settings.chainingAllowed = true
rs.reconfig(cfg)
←  Reconfigure a Replica Set with Unavailable MembersChange Hostnames in a Replica Set →