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.此过程描述如何禁用它以及如何重新启用它。
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.但该配置只会持续到辅助服务器重新计算要从哪个成员进行同步。
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
:
Copy the configuration settings into the 将配置设置复制到cfg
object:cfg
对象中:
cfg = rs.config()
Take note of whether the current configuration settings contain the 注意当前配置设置是否包含settings
embedded document. settings
嵌入文档。If they do, skip this step.如果有,请跳过此步骤。
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 = { }
Issue the following sequence of commands to set 发出以下命令序列以将settings.chainingAllowed
to false
:settings.chainingAllowed
设置为false
:
cfg.settings.chainingAllowed = false
rs.reconfig(cfg)
To re-enable chained replication, set 要重新启用链式复制,请将settings.chainingAllowed
to true
. settings.chainingAllowed
设置为true
。You can use the following sequence of commands:可以使用以下命令序列:
cfg = rs.config()
cfg.settings.chainingAllowed = true
rs.reconfig(cfg)