说明
replSetSyncFrom暂时覆盖当前
mongod的默认同步目标。 此操作对于测试不同模式以及集成员未从所需主机复制的情况非常有用。提示
In
mongosh, this command can also be run through thers.syncFrom()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.Run
replSetSyncFromin theadmindatabase.
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
重要
MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
语法
该命令具有以下语法:
db.adminCommand( { replSetSyncFrom: "hostname<:port>" } )
命令字段
该命令采用以下字段:
字段 | 类型 | 说明 |
|---|---|---|
| 字符串 | 该成员应从中进行复制的副本集成员的名称和端口号。 使用 副本集 |
行为
限制
For replSetSyncFrom to override the default sync target, settings.chainingAllowed must be set to true.
If settings.chainingAllowed is set to false, replSetSyncFrom returns ok:1 but does not set the sync target.
从MongoDB 5.0.2 开始,您可以通过将服务器参数 enableOverrideClusterChainingSetting 设置为 true 来覆盖 settings.chainingAllowed。即使 settings.chainingAllowed 为 false,这也允许从辅助节点成员进行同步。
同步逻辑
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:
For more information the use of replSetSyncFrom, see Configure a Self-Managed Secondary's Sync Target.