Docs 菜单

replSetSyncFrom

replSetSyncFrom

Temporarily overrides the default sync target for the current mongod. This operation is useful for testing different patterns and in situations where a set member is not replicating from the desired host.

提示

mongosh 中,该命令也可通过 rs.syncFrom() 辅助方法运行。

辅助方法对 mongosh 用户来说很方便,但它们返回的信息级别可能与数据库命令不同。如果不追求方便或需要额外的返回字段,请使用数据库命令。

Run replSetSyncFrom in the admin database.

此命令可用于以下环境中托管的部署:

重要

M0、M2、M5、M10+ 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。

该命令具有以下语法:

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

The command takes the following field:

字段
类型
说明

replSetSyncFrom

字符串

The name and port number of the replica set member that this member should replicate from. Use the [hostname]:[port] form.

Replica set members with 1 vote cannot sync from members with 0 votes.

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.

仅根据需要修改默认同步逻辑,并且始终谨慎操作。

要同步的节点必须是数据集中数据的有效来源。如需从节点同步,节点必须:

  • 有数据。在启动或恢复模式下不能是仲裁节点,必须能够响应数据查询。

  • 可访问。

  • 在副本集配置中是同一集的成员。

  • 使用 members[n].buildIndexes 设置构建索引。

  • 集合中的另一个成员,以防止与自身同步。

如果尝试从落后当前节点 10 秒以上的节点复制,mongod 将记录警告,但仍会从落后的节点复制。另请参阅“复制延迟和流量控制”。

replSetSyncFrom provide a temporary override of default behavior. mongod will revert to the default sync behavior in the following situations:

  • mongod 实例将重新启动。

  • mongod 与同步目标之间的连接将关闭。

  • 如果同步目标落后于副本集的其他节点超过 30 秒。

For more information the use of replSetSyncFrom, see 配置自管理辅助节点的同步目标.