Configure a Secondary’s Sync Target

Overview

Secondaries capture data from the primary member to maintain an up to datecopy of the sets’ data. However, by default secondaries may automaticallychange their sync targets to secondary members based on changes in theping time between members and the state of other members’ replication. SeeReplica Set Data Synchronization andManage Chained Replication for more information.

For some deployments, implementing a custom replication sync topology maybe more effective than the default sync target selection logic. MongoDBprovides the ability to specify a host to use as a sync target.

To temporarily override the default sync target selection logic, youmay manually configure a secondary member’s sync target totemporarily pull oplog entries. The following provide access tothis functionality:

Considerations

Sync Logic

Changed in version 3.4.

If an initial sync operation is in progress when you runreplSetSyncFrom/rs.syncFrom(), replSetSyncFrom/rs.syncFrom() stops the in-progress initial sync andrestarts the sync process with the new target. In previous versions,if you run replSetSyncFrom/rs.syncFrom() during initial sync, MongoDB produces noerror messages, but the sync target will not change until after theinitial sync operation.

Only modify the default sync logic as needed, and always exercisecaution.

Target

The member to sync from must be a valid source for data in the set.To sync from a member, the member must:

  • Have data. It cannot be an arbiter, in startup or recovering mode, andmust be able to answer data queries.
  • Be accessible.
  • Be a member of the same set in the replica set configuration.
  • Build indexes with themembers[n].buildIndexes setting.
  • A different member of the set, to prevent syncing from itself.

If you attempt to replicate from a member that is more than 10 secondsbehind the current member, mongod will log a warning but willstill replicate from the lagging member. See alsoReplication Lag and Flow Control.

Persistence

replSetSyncFrom/rs.syncFrom() provide a temporary override of default behavior.mongod will revert to the default sync behavior in thefollowing situations:

  • The mongod instance restarts.
  • The connection between the mongod and the sync targetcloses.
  • If the sync target falls more than 30 seconds behind anothermember of the replica set.

Procedure

To use the replSetSyncFrom command in the mongo shell:

  1. db.adminCommand( { replSetSyncFrom: "hostname<:port>" } );

To use the rs.syncFrom() helper in the mongo shell:

  1. rs.syncFrom("hostname<:port>");