- Replication >
- Replica Set Tutorials >
- Replica Set Maintenance Tutorials >
- Configure a Secondary’s Sync Target
Configure a Secondary’s Sync Target¶
On this page
Overview¶
Secondaries capture data from the primary member to maintain an up to date copy of the sets’ data. However, by default secondaries may automatically change their sync targets to secondary members based on changes in the ping time between members and the state of other members’ replication. See Replica Set Data Synchronization and Manage Chained Replication for more information.
For some deployments, implementing a custom replication sync topology may be more effective than the default sync target selection logic. MongoDB provides the ability to specify a host to use as a sync target.
To override the default sync target selection logic, you may manually configure a secondary member’s sync target to temporarily pull oplog entries. The following provide access to this functionality:
- replSetSyncFrom command, or
- rs.syncFrom() helper in the mongo shell
Considerations¶
Sync Logic¶
Only modify the default sync logic as needed, and always exercise caution. rs.syncFrom() will not affect an in-progress initial sync operation. To affect the sync target for the initial sync, run rs.syncFrom() operation before initial sync.
If you run rs.syncFrom() during initial sync, MongoDB produces no error messages, but the sync target will not change until after the initial sync operation.
Persistence¶
replSetSyncFrom and rs.syncFrom() provide a temporary override of default behavior. mongod will revert to the default sync behavior in the following situations:
Changed in version 2.4: The sync target falls more than 30 seconds behind another member of the replica set; the mongod will revert to the default sync target.
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, and must be able to answer data queries.
- Be accessible.
- Be a member of the same set in the replica set configuration.
- Build indexes with the members[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 seconds behind the current member, mongod will log a warning but will still replicate from the lagging member.
If you run replSetSyncFrom during initial sync, MongoDB produces no error messages, but the sync target will not change until after the initial sync operation.
Procedure¶
To use the replSetSyncFrom command in the mongo shell:
db.adminCommand( { replSetSyncFrom: "hostname<:port>" } );
To use the rs.syncFrom() helper in the mongo shell:
rs.syncFrom("hostname<:port>");
Thank you for your feedback!
We're sorry! You can Report a Problem to help us improve this page.