rs.syncFrom()
On this page本页内容
rs.syncFrom()
-
Temporarily overrides the default sync target for the current member.暂时覆盖当前成员的默认同步目标。Importantmongosh 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: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, 如果您试图从比当前成员晚10秒以上的成员进行复制,mongod
will log a warning but will still replicate from the lagging member. See also Replication Lag and Flow Control.mongod
将记录一条警告,但仍将从滞后成员进行复制。另请参阅复制滞后和流量控制。
Persistence坚持不懈
replSetSyncFrom
provide a temporary override of default behavior. 提供对默认行为的临时覆盖。mongod
will revert to the default sync behavior in the following situations:在以下情况下将恢复到默认的同步行为:
Example实例
To use the 要在rs.syncFrom()
helper in mongosh
:mongosh
中使用rs.syncFrom()
帮助程序:
rs.syncFrom("myHost:27017");