Docs HomeMongoDB Manual

rs.syncFrom()

On this page本页内容

rs.syncFrom()

Temporarily overrides the default sync target for the current member.暂时覆盖当前成员的默认同步目标。

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the replSetFreeze command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

mongo shell v4.4

Specify the name of the member you want to replicate from in the form of [hostname]:[port].[hostname]:[port]的形式指定要从中复制的成员的名称。

Behavior行为

Sync Logic同步逻辑

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将停止正在进行的初始同步,并重新启动与新目标的同步进程。

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. See also Replication Lag and Flow Control.如果您试图从比当前成员晚10秒以上的成员进行复制,mongod将记录一条警告,但仍将从滞后成员进行复制。另请参阅复制滞后和流量控制

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和同步目标之间的连接关闭。
  • 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: 另请参阅:

replSetSyncFrom