分库分表场景下的数据校验

    使用 对 table-0 进行特殊配置,设置 is-sharding=true,并且在 table-config.source-tables 中配置上游表信息。这种配置方式需要对所有分表进行设置,适合上游分表数量较少,且分表的命名规则没有规律的场景。场景如图所示:

    sync-diff-inspector 完整的示例配置如下:

    使用 table-rules 进行配置

    1. # Diff Configuration.
    2. ######################### Global config #########################
    3. # 日志级别,可以设置为 info、debug
    4. log-level = "info"
    5. # sync-diff-inspector 根据主键/唯一键/索引将数据划分为多个 chunk,
    6. # 对每一个 chunk 的数据进行对比。使用 chunk-size 设置 chunk 的大小
    7. chunk-size = 1000
    8. # 检查数据的线程数量
    9. check-thread-count = 4
    10. # 抽样检查的比例,如果设置为 100 则检查全部数据
    11. sample-percent = 100
    12. # 通过计算 chunk 的 checksum 来对比数据,如果不开启则逐行对比数据
    13. use-checksum = true
    14. # 如果设置为 true 则只会通过计算 checksum 来校验数据,如果上下游的 checksum 不一致也不会查出数据再进行校验
    15. only-use-checksum = false
    16. # 不对比数据
    17. ignore-data-check = false
    18. # 不对比表结构
    19. ignore-struct-check = false
    20. # 保存用于修复数据的 sql 的文件名称
    21. fix-sql-file = "fix.sql"
    22. ######################### Tables config #########################
    23. # 配置需要对比的目标数据库中的表
    24. [[check-tables]]
    25. # 库的名称
    26. schema = "test"
    27. # 需要检查的表的名称
    28. tables = ["table-0"]
    29. # 通过 table-rule 来设置上游分表与下游总表的映射关系。可以只配置 schema 或者 table 的映射关系,也可以都配置
    30. [[table-rules]]
    31. # schema-pattern 和 table-pattern 支持通配符 *?
    32. # 在 source-db 中配置的上游数据库中所有满足 schema-pattern 和 table-pattern 规则的表都为 target-schema.target-table 的分表
    33. schema-pattern = "test"
    34. table-pattern = "table-*"
    35. target-table = "table-0"
    36. ######################### Databases config #########################
    37. # 源数据库实例的配置
    38. [[source-db]]
    39. host = "127.0.0.1"
    40. port = 3306
    41. user = "root"
    42. password = "123456"
    43. instance-id = "MySQL-1"
    44. # 源数据库实例的配置
    45. [[source-db]]
    46. host = "127.0.0.2"
    47. port = 3306
    48. user = "root"
    49. password = "123456"
    50. instance-id = "MySQL-2"
    51. # 目标数据库实例的配置
    52. [target-db]
    53. host = "127.0.0.3"
    54. port = 4000
    55. user = "root"
    56. password = "123456"