Manage Chained Replication

Starting in version 2.0, MongoDB supports chained replication. Achained replication occurs when a secondary member replicatesfrom another secondary member instead of from the primary. Thismight be the case, for example, if a secondary selects its replicationtarget based on ping time and if the closest member is anothersecondary.

Chained replication can reduce load on the primary. But chainedreplication can also result in increased replication lag, depending onthe topology of the network.

You can use the settings.chainingAllowedsetting in Replica Set Configuration to disable chainedreplication for situations where chained replication is causing lag.

MongoDB enables chained replication by default. This proceduredescribes how to disable it and how to re-enable it.

Note

If chained replication is disabled, you still can usereplSetSyncFrom to specify that a secondary replicatesfrom another secondary. But that configuration will last only until thesecondary recalculates which member to sync from.

Disable Chained Replication

To disable chained replication, set thesettings.chainingAllowedfield in Replica Set Configuration to false.

You can use the following sequence of commands to setsettings.chainingAllowed tofalse:

  • Copy the configuration settings into the cfg object:
  1. cfg = rs.config()
  • Take note of whether the current configuration settings contain thesettings embedded document. If they do, skip this step.

Warning

To avoid data loss, skip this step if the configurationsettings contain the settings embedded document.

If the current configuration settings do not contain thesettings embedded document, create the embedded document by issuing thefollowing command:

  1. cfg.settings = { }
  1. cfg.settings.chainingAllowed = false
  2. rs.reconfig(cfg)

Re-enable Chained Replication

To re-enable chained replication, setsettings.chainingAllowed to true.You can use the following sequence of commands:

  1. cfg = rs.config()
  2. cfg.settings.chainingAllowed = true
  3. rs.reconfig(cfg)