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. 但是,默认情况下,辅助可以根据成员之间的ping时间和其他成员的复制状态的变化,自动将其同步目标更改为辅助成员。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.对于某些部署,实现自定义复制同步拓扑可能比默认同步目标选择逻辑更有效。MongoDB提供了指定主机作为同步目标的功能。
To temporarily 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:要临时覆盖默认同步目标选择逻辑,可以手动配置secondary成员的同步目标以临时拉取oplog条目。以下提供了对此功能的访问权限:
replSetSyncFrom
command, or命令,或rs.syncFrom()
helper inmongosh
mongosh
中的rs.syncFrom()
助手
Considerations注意事项
Sync Logic同步逻辑
If an initial sync operation is in progress when you run 如果在运行replSetSyncFrom
/rs.syncFrom()
, replSetSyncFrom
/rs.syncFrom()
stops the in-progress initial sync and restarts the sync process with the new target.replSetSyncFrom
/rs.syncFrom()
时正在进行初始同步操作,则replSetSyncFrom
/rs.syncFrom()
将停止正在进行的初始同步,并重新启动与新目标的同步进程。
Only modify the default sync logic as needed, and always exercise caution.仅根据需要修改默认同步逻辑,并始终保持谨慎。
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.members[n].buildIndexes
设置生成索引。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, 如果您试图从比当前成员晚10秒以上的成员进行复制,mongod
will log a warning but will still replicate from the lagging member. mongod
将记录一条警告,但仍将从滞后成员进行复制。 See also Replication Lag and Flow Control.另请参阅复制滞后和流量控制。
Persistence坚持不懈
replSetSyncFrom
/rs.syncFrom()
provide a temporary override of default behavior. 提供对默认行为的临时覆盖。mongod
will revert to the default sync behavior in the following situations:在以下情况下将恢复到默认的同步行为:
Procedure过程
To use the 要在replSetSyncFrom
command in mongosh
:mongosh
中使用replSetSyncFrom
命令,请执行以下操作:
db.adminCommand( { replSetSyncFrom: "hostname<:port>" } );
To use the 要在rs.syncFrom()
helper in mongosh
:mongosh
中使用rs.syncFrom()
帮助程序:
rs.syncFrom("hostname<:port>");