Manage Chained Replication管理链式复制
On this page本页内容
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.此过程描述了如何禁用它以及如何重新启用它。
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
:
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.如果是,请跳过此步骤。WarningTo 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
tofalse
: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)