The mongosync program uses change streams to synchronize data between source and destination clusters. mongosync does not access the oplog directly, but when a change stream returns events from the past, the events must be within the oplog time range.
mongosync 在 集合复制 阶段之后,将源集群上 oplog 中的操作应用于目标集群上的数据。当 mongosync 未应用的操作滚动源集群上的 oplog 时,同步将失败并且 mongosync 退出。
注意
mongosync does not replicate applyOps operations made on the source cluster during sync to the destination cluster.
If you anticipate syncing a large data set, or if you plan to pause synchronization for an extended period of time, you might exceed the oplog window. Use the oplogSizeMB setting to increase the size of the oplog on the source cluster.
Considerations
目标集群必须有足够的磁盘存储,以容纳正在迁移的逻辑数据大小以及初始同步中的目标oplog条目。 示例,要迁移10 GB的数据,目标集群必须至少有 10 GB用于数据,另外 10 GB用于初始同步中的插入oplog条目。
要使用嵌入式验证,目标上必须有更大的oplog 。如果启用嵌入式验证程序并减小目标oplog的大小,则嵌入式验证程序可能无法跟上,从而导致 mongosync 出错。
如果需要减少目标oplog条目的开销并且嵌入式验证程序已禁用,则可以:
Use the
oplogSizeMBsetting to lower the destination cluster's oplog size.Use to
oplogMinRetentionHourssetting to lower or remove the destination cluster's minimum oplog retention period.
监控初始同步所需的 oplog 大小
确定 oplog window
To get the difference in seconds between the first and last entry in the oplog run db.getReplicationInfo(). If you are replicating a sharded cluster, run the command on each shard.
db.getReplicationInfo().timeDiff
返回的值是集群的最小oplog窗口。 如果有多个分片,则最小的数字是最小oplog窗口。
确定 mongosync 复制延迟
要获取lagTimeSeconds值,请运行/progress命令。 延迟时间是指mongosync应用的最后一个事件与源集群上的当前最新事件的时间之间的时间(以秒为单位)。
它用于衡量落后于源集群mongosync的程度。
验证 oplog 大小
如果延迟时间接近最小oplog窗口,请进行以下更改之一:
Increase the
oplogwindow. UsereplSetResizeOplogto setminRetentionHoursgreater than the currentoplogwindow.注意
replSetResizeOplogis unsupported in Atlas. To resize the oplog in Atlas, see Set Minimum Oplog Window.扩展
mongosync实例。 添加 CPU 或内存以纵向扩展mongosync节点,使其具有更高的复制速率。
注意
同步期间,复制延迟的oplog窗口和变化率可能会发生变化。 在迁移过程中重复这些步骤以监控进度。