rs.syncFrom()

On this page本页内容

rs.syncFrom()

Provides a wrapper around the replSetSyncFrom, which allows administrators to temporarily override the default sync target for the current member. 提供replSetSyncFrom的包装,允许管理员临时覆盖当前成员的默认同步目标。Specify the name of the member you want to replicate from in the form of [hostname]:[port].指定要从中复制的成员的名称,格式为[hostname]:[port]

Changed in version 3.2.在版本3.2中更改

MongoDB 3.2 replica set members with 1 vote cannot sync from members with 0 votes.具有1 vote的MongoDB 3.2副本集成员无法与具有0 votes成员同步。

Behavior行为

Sync Logic同步逻辑

Changed in version 3.4.在版本3.4中更改

If an initial sync operation is in progress when you run replSetSyncFrom, replSetSyncFrom stops the in-progress initial sync and restarts the sync process with the new target. 如果在运行replSetSyncFrom时正在进行初始同步操作,replSetSyncFrom将停止正在进行的初始同步,并重新启动与新目标的同步进程。In previous versions, 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.在以前的版本中,如果在初始同步期间运行replSetSyncFrom,MongoDB不会生成错误消息,但同步目标在初始同步操作之后才会更改。

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, mongod will log a warning but will still replicate from the lagging member. 如果您尝试从比当前成员落后10秒以上的成员进行复制,mongod将记录一条警告,但仍将从落后成员进行复制。See also Replication Lag and Flow Control.另请参见复制滞后和流控制

Persistence坚持不懈

replSetSyncFrom provide a temporary override of default behavior. 提供默认行为的临时覆盖。mongod will revert to the default sync behavior in the following situations:在以下情况下将恢复为默认同步行为:

  • The mongod instance restarts.mongod实例重新启动。
  • The connection between the mongod and the sync target closes.mongod和sync目标之间的连接关闭。
  • If the sync target falls more than 30 seconds behind another member of the replica set.如果同步目标落后副本集的另一个成员30秒以上。

Example示例

To use the rs.syncFrom() helper in mongosh:要在mongosh中使用rs.syncFrom()助手,请执行以下操作:

rs.syncFrom("myHost:27017");
Tip提示
See also: 参阅:
←  rs.stepDown()Sharding Methods →