1.9版本新增。
mongosync 包括一个嵌入式验证器,用于对目标集群执行一系列检查,以验证支持的集合的同步。默认下,mongosync 在副本集集群上启用验证程序。
从版本 1.10 开始,mongosync默认在分片的集群上启用验证程序。
从版本 1.22 开始,验证程序默认在变更事件应用程序 (CEA) 阶段开始运行。大多数运行验证的迁移会更快、更可靠地完成。由于验证程序现在在 CEA 阶段启动,因此 /progress 端点会在集合复制期间将验证程序 phase 报告为 "not started"。
注意
mongosync reads using primary read preference, so it preserves document field order from the source cluster's primary node. The embedded verifier also checks documents based on the source cluster’s primary node, but at a different time from when mongosync reads them. Because of this, in rare cases, discrepancies in document field order between the source cluster’s nodes can cause the embedded verifier to fail the migration, even if mongosync copied the documents correctly.
关于此任务
兼容性
嵌入式验证器在 Mongosync 1.8 及更早版本中不可用。
限制
嵌入式验证程序具有以下限制:
mongosync将验证者状态存储在内存中,这可能会导致大量内存开销。 要运行验证程序,mongosync大约需要 10 GB内存,此外,每 1 万份文档需要额外 500 MB 内存。验证程序无法恢复。 如果用户停止或暂停同步,然后因任何原因再次启动
mongosync,验证进程将从头开始。 这可能会导致验证大大落后于迁移。
不支持的验证检查
验证程序不会检查以下命名空间:
固定大小集合
具有TTL索引的集合,包括在迁移过程中添加或删除的TTL索引
不使用默认的集合
要验证不支持的集合,请添加其他脚本代码来检查集合。有关详细信息,请参阅验证数据传输。
注意
从版本1.10 开始,验证程序会检查 之前版本上发生的 DDL事件是否存在数据不一致。6.0迁移期间的源集群。 这是因为 6.0 迁移不支持DDL 事件。
要学习;了解更多信息,请参阅 6.0之前的迁移限制。
步骤
初始化 mongosync
初始化 mongosync进程:
./bin/mongosync \ --logPath /var/log/mongosync \ --cluster0 "mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020" \ --cluster1 "mongodb://clusterAdmin:superSecret@clusterTwo01.fancyCorp.com:20020,clusterTwo02.fancyCorp.com:20020,clusterTwo03.fancyCorp.com:20020"
启动同步
要开始将数据从源集群同步到目标,请使用 /start 端点。
curl localhost:27182/api/v1/start -XPOST \ --data ' { "source": "cluster0", "destination": "cluster1", } '
示例输出:
{"success":true}
检查进度
要检查同步的状态,请使用 /progress 端点:
curl localhost:27182/api/v1/progress -XGET
示例输出:
{ "progress": { "state":"RUNNING", "canCommit":true, "canWrite":false, "info":"change event application", "ceaStage":"steady state", "lag": { "overallLagSeconds": 0, "crudLagSeconds": 0, "ddlLagSeconds": null }, "lagTimeSeconds":0, "collectionCopy": { "estimatedTotalBytes":694, "estimatedCopiedBytes":694 }, "directionMapping": { "Source":"cluster0: localhost:27017", "Destination":"cluster1: localhost:27018" }, "source": { "pingLatencyMs":250 }, "destination": { "pingLatencyMs":-1 }, "verification": { "source": { "estimatedDocumentCount": 42, "hashedDocumentCount": 42, "lagTimeSeconds": 2, "totalCollectionCount": 42, "scannedCollectionCount": 10, "phase": "stream hashing" }, "destination": { "estimatedDocumentCount": 42, "hashedDocumentCount": 42, "lagTimeSeconds": 2, "totalCollectionCount": 42, "scannedCollectionCount": 10, "phase": "stream hashing" } } }, "success": true }
检查 verification 响应字段,获取有关嵌入式验证程序状态的信息。
行为
验证检查
嵌入式验证程序对目标集群执行一系列检查。 它会检查所有支持的集合,以确认 mongosync 已成功将文档从源集群传输到目标。
如果验证程序遇到错误,则会导致迁移失败并显示错误。 如果验证程序未发现错误,/progress 端点将返回 canWrite: true。 要学习;了解有关canWrite 字段的更多信息,请参阅 canWrite 和 COMMITTED。
从版本 1.15 开始,嵌入式验证程序会检查集合元数据、索引和视图。如果验证器在元数据验证期间发现不匹配,则会返回包含不匹配类型及其出现次数的错误。
Please contact support to investigate verification issues.
内存要求
验证需要 10 GB的内存,此外,迁移中每 1 百万个文档还需要 500 MB 的内存。
如果可用内存不足,/start 端点将返回错误。 如果发生这种情况,要将 mongosync 与验证程序一起使用,必须首先增加服务器的内存并恢复迁移。
如果增加服务器内存不可行,请在禁用验证器的情况下重新启动mongosync 。