sync-diff-inspector是否支持上下游均为tidb,而且库名与表名均相同的同步任务,如果支持的话,麻烦看下我这个为什么会报错,是配置文件有问题吗

sync-diff-inspector是否支持上下游均为tidb,而且库名与表名均相同的同步任务,如果支持的话,麻烦看下我这个为什么会报错,是配置文件有问题吗

配置:


# Diff Configuration.

######################### Global config #########################

# 检查数据的线程数量,上下游数据库的连接数会略大于该值

check-thread-count = 4

# 如果开启,若表存在不一致,则输出用于修复的 SQL 语句。

export-fix-sql = true

# 只对比表结构而不对比数据

check-struct-only = false

######################### Datasource config #########################

[data-sources]

[data-sources.mysql1] # mysql1 是该数据库实例唯一标识的自定义 id,用于下面 task.source-instances/task.target-instance 中

host = "10.30.23.126"

port = 3306

user = "root"

password = "TiDB666=$"

route-rules = ["rule1"]

#[data-sources.mysql2] # mysql1 是该数据库实例唯一标识的自定义 id,用于下面 task.source-instances/task.target-instance 中

# host = "10.30.23.192"

# port = 3306

# user = "root"

# password = "TiDB666=$"

#(可选)使用映射规则来匹配上游多个分表,其中 rule1 和 rule2 在下面 Routes 配置栏中定义

#route-rules = ["rule1", "rule2"]

# route-rules = ["rule1"]

[data-sources.tidb0]

host = "10.30.23.176"

port = 3306

user = "root"

password = "TiDB666=$"

#(可选)使用 TiDB 的 snapshot 功能,如果开启的话会使用历史数据进行对比

# snapshot = "442935976656896001"

########################### Routes ###########################

# 如果需要对比大量的不同库名或者表名的表的数据,或者用于校验上游多个分表与下游总表的数据,可以通过 table-rule 来设置映射关系

# 可以只配置 schema 或者 table 的映射关系,也可以都配置

[routes]

[routes.rule1] # rule1 是该配置的唯一标识的自定义 id,用于上面 data-sources.route-rules 中

schema-pattern = "SJZX" # 匹配数据源的库名,支持通配符 "*" 和 "?"

table-pattern = "TAB_110_FKB" # 匹配数据源的表名,支持通配符 "*" 和 "?"

#table-pattern = "*"

target-schema = "SJZX" # 目标库名

target-table = "TAB_110_FKB" # 目标表名

#target-table = "new"

#[routes.rule2]

#schema-pattern = "test2_*" # 匹配数据源的库名,支持通配符 "*" 和 "?"

#table-pattern = "t2_*" # 匹配数据源的表名,支持通配符 "*" 和 "?"

#target-schema = "test2" # 目标库名

#target-table = "t2" # 目标表名

######################### Task config #########################

# 配置需要对比的*目标数据库*中的表

[task]

# output-dir 会保存如下信息

# 1 sql: 检查出错误后生成的修复 SQL 文件,并且一个 chunk 对应一个文件

# 2 log: sync-diff.log 保存日志信息

# 3 summary: summary.txt 保存总结

# 4 checkpoint: a dir 保存断点续传信息

output-dir = "./output"

# 上游数据库,内容是 data-sources 声明的唯一标识 id

source-instances = ["mysql1"]

# 下游数据库,内容是 data-sources 声明的唯一标识 id

target-instance = "tidb0"

# 需要比对的下游数据库的表,每个表需要包含数据库名和表名,两者由 `.` 隔开

# 使用 ? 来匹配任意一个字符;使用 * 来匹配任意;详细匹配规则参考 golang regexp pkg: https://github.com/google/re2/wiki/Syntax

target-check-tables = ["SJZX.TAB_110_FKB"]

#(可选)对部分表的额外配置,其中 config1 在下面 Table config 配置栏中定义

# target-configs = ["config1"]

######################### Table config #########################

# 对部分表进行特殊的配置,配置的表必须包含在 task.target-check-tables 中

#[table-configs.config1] # config1 是该配置的唯一标识自定义 id,用于上面 task.target-configs 中

# 目标表名称,可以使用正则来匹配多个表,但不允许存在一个表同时被多个特殊配置匹配。

#target-tables = ["SJZX.TAB_110_FKB"]

#(可选)指定检查的数据的范围,需要符合 sql 中 where 条件的语法

#range = "age > 10 AND age < 20"

#(可选)指定用于划分 chunk 的列,如果不配置该项,sync-diff-inspector 会选取一些合适的列(主键/唯一键/索引)

#index-fields = ["col1","col2"]

#(可选)忽略某些列的检查,例如 sync-diff-inspector 目前还不支持的一些类型(json,bit,blob 等),

# 或者是浮点类型数据在 TiDB 和 MySQL 中的表现可能存在差异,可以使用 ignore-columns 忽略检查这些列

#ignore-columns = ["",""]

#(可选)指定划分该表的 chunk 的大小,若不指定可以删去或者将其配置为 0。

#chunk-size = 0

#(可选)指定该表的 collation,若不指定可以删去或者将其配置为空字符串。

#collation = ""

报错日志:


[2023/07/18 16:32:16.918 +08:00] [INFO] [printer.go:46] ["Welcome to sync_diff_inspector"] ["Release Version"=v6.1.1-dirty] ["Git Commit Hash"=b505953aaa9ed289b71f3000cb7cb54fd09cd3e2] ["Git Branch"=heads/refs/tags/v6.1.1] ["UTC Build Time"="2022-08-23 08:25:33"] ["Go Version"=go1.18.5]

[2023/07/18 16:32:16.919 +08:00] [INFO] [main.go:101] [config="{\"check-thread-count\":4,\"split-thread-count\":5,\"export-fix-sql\":true,\"check-struct-only\":false,\"dm-addr\":\"\",\"dm-task\":\"\",\"data-sources\":{\"mysql1\":{\"host\":\"10.30.23.126\",\"port\":3306,\"user\":\"root\",\"password\":\"TiDB666=$\",\"sql-mode\":\"\",\"snapshot\":\"\",\"route-rules\":[\"rule1\"],\"Router\":{\"Selector\":{}},\"Conn\":null},\"tidb0\":{\"host\":\"10.30.23.176\",\"port\":3306,\"user\":\"root\",\"password\":\"TiDB666=$\",\"sql-mode\":\"\",\"snapshot\":\"\",\"route-rules\":null,\"Router\":{\"Selector\":{}},\"Conn\":null}},\"routes\":{\"rule1\":{\"schema-pattern\":\"sjzx\",\"table-pattern\":\"tab_110_fkb\",\"target-schema\":\"SJZX\",\"target-table\":\"TAB_110_FKB\"}},\"table-configs\":null,\"task\":{\"source-instances\":[\"mysql1\"],\"source-routes\":null,\"target-instance\":\"tidb0\",\"target-check-tables\":[\"SJZX.TAB_110_FKB\"],\"target-configs\":null,\"output-dir\":\"./output\",\"SourceInstances\":[{\"host\":\"10.30.23.126\",\"port\":3306,\"user\":\"root\",\"password\":\"TiDB666=$\",\"sql-mode\":\"\",\"snapshot\":\"\",\"route-rules\":[\"rule1\"],\"Router\":{\"Selector\":{}},\"Conn\":null}],\"TargetInstance\":{\"host\":\"10.30.23.176\",\"port\":3306,\"user\":\"root\",\"password\":\"TiDB666=$\",\"sql-mode\":\"\",\"snapshot\":\"\",\"route-rules\":null,\"Router\":{\"Selector\":{}},\"Conn\":null},\"TargetTableConfigs\":null,\"TargetCheckTables\":[{}],\"FixDir\":\"output/fix-on-tidb0\",\"CheckpointDir\":\"output/checkpoint\",\"HashFile\":\"\"},\"ConfigFile\":\"./sync.yaml\",\"PrintVersion\":false}"]

[2023/07/18 16:32:16.935 +08:00] [FATAL] [main.go:120] ["failed to initialize diff process"] [error="add shield rule failed [schema = SJZX] [table = TAB_110_FKB]"] [errorVerbose="add shield rule failed [schema = SJZX] [table = TAB_110_FKB]\ngithub.com/pingcap/tidb-tools/sync_diff_inspector/source.NewSources\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb-tools/sync_diff_inspector/source/source.go:156\nmain.(*Diff).init\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb-tools/sync_diff_inspector/diff.go:139\nmain.NewDiff\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb-tools/sync_diff_inspector/diff.go:97\nmain.checkSyncState\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb-tools/sync_diff_inspector/main.go:117\nmain.main\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb-tools/sync_diff_inspector/main.go:104\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:250\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1571"] [stack="main.checkSyncState\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb-tools/sync_diff_inspector/main.go:120\nmain.main\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb-tools/sync_diff_inspector/main.go:104\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:250"]

库名和表名都是大写吗?

肯定是支持的,我最近刚做了上下游比对。上下游库表名都相同,那把路由相关的都删了再试试。

这是我之前比对单表的一个配置文件,可以参考下

check-thread-count = 16
export-fix-sql = true
check-struct-only = false
 
[data-sources]
[data-sources.tidb1]
 
    host = "xx.xx.xx.xx"
    port = 4000
    user = "xxx"
    password = "xxxx"
    snapshot = "442818765228867661"
[data-sources.tidb2]
 
    host = "xx.xx.xx.x"
    port = 4000
    user = "xxxx"
    password = "xxxx"
    snapshot = "442818765259538435"
[task]
 
    output-dir = "./output"
    source-instances = ["tidb1"]
    target-instance = "tidb2"
    target-check-tables = ["xxx.xxx"]
    target-configs = ["config1"]
[table-configs.config1] # config1 是该配置的唯一标识自定义 id,用于上面 task.target-configs 中
chunk-size = 10000000

同样的问题,蹲

是的,都是大写

是不是你配置了snapshot ,如果不配置好像不行诶

支持。权限咋配置的

什么的权限,配置文件在最上面呢

感觉还是配置问题,推荐试试上面 啦啦啦啦啦 发的配置试试。

嗯,我又试了几次,把下面这个route注释了就可以了,这是什么原因呢

route-rules = [“rule1”]

此话题已在最后回复的 60 天后被自动关闭。不再允许新回复。