【 TiDB 使用环境】生产\测试环境\ POC
生产
【 TiDB 版本】
4.0.15
【遇到的问题】
增量恢复出现唯一键冲突
[2022/06/23 19:01:40.184 +08:00] [ERROR] [db.go:81] ["execute ddl query failed"] [query="ALTER TABLE `supplier_environment_total` ADD UNIQUE `uk_key_code`(`key_code`)"] [db=supply_chain_factory] [historySchemaVersion=2360] [error="[kv:1062]Duplicate entry '' for key 'uk_key_code'"] [errorVerbose="[kv:1062]Duplicate entry '' for key 'uk_key_code'\
github.com/pingcap/errors.AddStack\
\tgithub.com/pingcap/errors@v0.11.5-0.20201126102027-b0a155152ca3/errors.go:174\
github.com/pingcap/errors.Trace\
\tgithub.com/pingcap/errors@v0.11.5-0.20201126102027-b0a155152ca3/juju_adaptor.go:15\
github.com/pingcap/tidb/ddl.(*ddl).doDDLJob\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/ddl/ddl.go:578\
github.com/pingcap/tidb/ddl.(*ddl).CreateIndex\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/ddl/ddl_api.go:4034\
github.com/pingcap/tidb/ddl.(*ddl).AlterTable\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/ddl/ddl_api.go:2117\
github.com/pingcap/tidb/executor.(*DDLExec).executeAlterTable\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/executor/ddl.go:366\
github.com/pingcap/tidb/executor.(*DDLExec).Next\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/executor/ddl.go:86\
github.com/pingcap/tidb/executor.Next\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/executor/executor.go:262\
github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/executor/adapter.go:531\
github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelay\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/executor/adapter.go:413\
github.com/pingcap/tidb/executor.(*ExecStmt).Exec\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/executor/adapter.go:366\
github.com/pingcap/tidb/session.runStmt\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/session/tidb.go:322\
github.com/pingcap/tidb/session.(*session).ExecuteStmt\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/session/session.go:1381\
github.com/pingcap/tidb/session.(*session).ExecuteInternal\
\tgithub.com/pingcap/tidb@v1.1.0-beta.0.20210714111333-67b641d5036c/session/session.go:1132\
github.com/pingcap/br/pkg/gluetidb.(*tidbSession).Execute\
\tgithub.com/pingcap/br@/pkg/gluetidb/glue.go:109\
github.com/pingcap/br/pkg/restore.(*DB).ExecDDL\
\tgithub.com/pingcap/br@/pkg/restore/db.go:79\
github.com/pingcap/br/pkg/restore.(*Client).ExecDDLs\
\tgithub.com/pingcap/br@/pkg/restore/client.go:500\
github.com/pingcap/br/pkg/task.RunRestore\
\tgithub.com/pingcap/br@/pkg/task/restore.go:292\
main.runRestoreCommand\
\tgithub.com/pingcap/br@/cmd/br/restore.go:25\
main.newFullRestoreCommand.func1\
\tgithub.com/pingcap/br@/cmd/br/restore.go:97\
github.com/spf13/cobra.(*Command).execute\
\tgithub.com/spf13/cobra@v1.0.0/command.go:842\
github.com/spf13/cobra.(*Command).ExecuteC\
\tgithub.com/spf13/cobra@v1.0.0/command.go:950\
github.com/spf13/cobra.(*Command).Execute\
\tgithub.com/spf13/cobra@v1.0.0/command.go:887\
main.main\
\tgithub.com/pingcap/br@/cmd/br/main.go:56\
runtime.main\
\truntime/proc.go:203\
runtime.goexit\
\truntime/asm_amd64.s:1357"] [stack="github.com/pingcap/br/pkg/restore.(*DB).ExecDDL\
\tgithub.com/pingcap/br@/pkg/restore/db.go:81\
github.com/pingcap/br/pkg/restore.(*Client).ExecDDLs\
\tgithub.com/pingcap/br@/pkg/restore/client.go:500\
github.com/pingcap/br/pkg/task.RunRestore\
\tgithub.com/pingcap/br@/pkg/task/restore.go:292\
main.runRestoreCommand\
\tgithub.com/pingcap/br@/cmd/br/restore.go:25\
main.newFullRestoreCommand.func1\
\tgithub.com/pingcap/br@/cmd/br/restore.go:97\
github.com/spf13/cobra.(*Command).execute\
\tgithub.com/spf13/cobra@v1.0.0/command.go:842\
github.com/spf13/cobra.(*Command).ExecuteC\
\tgithub.com/spf13/cobra@v1.0.0/command.go:950\
github.com/spf13/cobra.(*Command).Execute\
\tgithub.com/spf13/cobra@v1.0.0/command.go:887\
main.main\
\tgithub.com/pingcap/br@/cmd/br/main.go:56\
runtime.main\
\truntime/proc.go:203"]
经排查, BR恢复的时候, 先恢复ddl, 再恢复数据, 这种逻辑在恢复全备是没有问题,但是恢复增备有问题,比如
一个表
t1 做ddl 加列, 默认值是1
t2, 修改默认值, 消除重复重
t3, 加唯一索引
时间关系: t1< t2 < t3
如果先做ddl , 即加执行加列, 然后再加唯一索引,最后再恢复数据 就会现在
唯一键冲突问题。
关于BR 增量恢复我看了一个文章, 4.x, 5.x 是正式功能, 结果到了6.x 就变成试验功能了, 是发现这里面有BUG 吗?
【复现路径】做过哪些操作出现的问题
【问题现象及影响】
【附件】
- 相关日志、配置文件、Grafana 监控(https://metricstool.pingcap.com/)
- TiUP Cluster Display 信息
- TiUP CLuster Edit config 信息
- TiDB-Overview 监控
- 对应模块的 Grafana 监控(如有 BR、TiDB-binlog、TiCDC 等)
- 对应模块日志(包含问题前后 1 小时日志)
若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出的打印结果,请务必全选并复制粘贴上传。