点击上方“IT那活儿”,关注后了解更多内容,不管IT什么活儿,干就完了!!!

情况1:上游数据存在冲突的情况,例如上游两套Mysql库,分别都有store_bj表,通过DM将上游两张表的数据汇总到下游一张表中,在同步的过程中上游两张表都有id=12的主键的数据,上游mysql中均插入成功,但在同步Tidb进行中出现主键冲突。
create table store_bj (id int primary key,name varchar(20));mysql1:mysql> insert into store_bj values (12,'store_bj_11');Query OK, 1 row affected (0.01 sec)mysql2:mysql> insert into store_bj values (12,'store_bj_12');Query OK, 1 row affected (0.01 sec)
[tidb@tidb1 ~]$ tiup dmctl --master-addr ***.**.***.134:8261 query-status two_tidb_slave………"subTaskStatus": [{"name": "two_tidb_slave","stage": "Paused","unit": "Sync","result": {"isCanceled": false,"errors": [{"ErrCode": 100*6,"ErrClass": "database","ErrScope": "not-set","ErrLevel": "high","Message": "startLocation: [position: (, 0), gtid-set: ], endLocation: [position: (mysql-bin.000002, 12368), gtid-set: ]: execute statement failed: commit", "RawCause": "Error 1062: Duplicate entry '12' for key 'PRIMARY'","Workaround": ""}],"detail": null…………
[tidb@tidb1 ~]$ cat home/tidb/dm/deploy/dm-worker-8262/log/dm-worker.log………[2021/12/03 16:54:39.773 +08:00] [INFO] [syncer.go:1902] ["meet heartbeat event and then flush jobs"] [task=two_tidb_slave] [unit="binlog replication"][2021/12/03 16:54:39.773 +08:00] [INFO] [syncer.go:3016] ["flush all jobs"] [task=two_tidb_slave] [unit="binlog replication"] ["global checkpoint"="position: (mysql-bin.000002, 12123), gtid-set: (flushed position: (mysql-bin.000002, 12123), gtid-set: )"][2021/12/03 16:54:39.773 +08:00] [INFO] [syncer.go:1119] ["flushed checkpoint"] [task=two_tidb_slave] [unit="binlog replication"] [checkpoint="position: (mysql-bin.000002, 12123), gtid-set: (flushed position: (mysql-bin.000002, 12123), gtid-set: )"][2021/12/03 16:54:39.773 +08:00] [INFO] [syncer.go:1127] ["after last flushing checkpoint, DM has ignored row changes by expression filter"] [task=two_tidb_slave] [unit="binlog replication"] ["number of filtered insert"=0] ["number of filtered update"=0] ["number of filtered delete"=0][2021/12/03 16:54:41.794 +08:00] [ERROR] [db.go:201] ["execute statements failed after retry"] [task=two_tidb_slave] [unit="binlog replication"] [queries="[INSERT INTO `store`.`store_bj` (`id`,`name`) VALUES (?,?)]"] [arguments="[[12 store_bj_12]]"] [error="[code=10006:class=database:scope=not-set:level=high], Message: execute statement failed: commit, RawCause: Error 1062: Duplicate entry '12' for key 'PRIMARY'"][2021/12/03 16:54:41.794 +08:00] [INFO] [syncer.go:2854] ["print status routine exits"] [task=two_tidb_slave] [unit="binlog replication"] [error="context canceled"][2021/12/03 16:54:41.794 +08:00] [INFO] [syncer.go:1696] ["binlog replication main routine quit(context canceled)!"] [task=two_tidb_slave] [unit="binlog replication"] ["last location"="position: (mysql-bin.000002, 12399), gtid-set: "][2021/12/03 16:54:41.828 +08:00] [INFO] [syncer.go:1602] ["flush checkpoints when exit task"] [task=two_tidb_slave] [unit="binlog replication"][2021/12/03 16:54:41.837 +08:00] [INFO] [checkpoint.go:694] ["rollback checkpoint"] [task=two_tidb_slave] [unit="binlog replication"] [component="remote checkpoint"] [schema=store] [table=store_shenzhen] [from="position: (mysql-bin.000002, 10712), gtid-set: "] [to="position: (mysql-bin.000002, 10712), gtid-set: "][2021/12/03 16:54:41.837 +08:00] [WARN] [checkpoint.go:697] ["failed to drop table from schema tracker"] [task=two_tidb_slave] [unit="binlog replication"] [component="remote checkpoint"] [schema=store] [table=store_shenzhen] [error="[schema:1146]Table 'store.store_shenzhen' doesn't exist"][2021/12/03 16:54:41.844 +08:00] [WARN] [syncer.go:681] ["something wrong with rollback global checkpoint"] [task=two_tidb_slave] [unit="binlog replication"] ["previous position"="position: (mysql-bin.000002, 12399), gtid-set: "] ["current position"="position: (mysql-bin.000002, 12123), gtid-set: "][2021/12/03 16:54:41.844 +08:00] [INFO] [subtask.go:292] ["unit process returned"] [subtask=two_tidb_slave] [unit=Sync] [stage=Paused] [status="{\"totalEvents\":1,\"syncerBinlog\":\"(mysql-bin.000002, 12123)\",\"binlogType\":\"remote\"}"][2021/12/03 16:54:41.844 +08:00] [ERROR] [subtask.go:311] ["unit process error"] [subtask=two_tidb_slave] [unit=Sync] ["error information"="{\"ErrCode\":10006,\"ErrClass\":\"database\",\"ErrScope\":\"not-set\",\"ErrLevel\":\"high\",\"Message\":\"startLocation: [position: (, 0), gtid-set: ], endLocation: [position: (mysql-bin.000002, 12368), gtid-set: ]: execute statement failed: commit\",\"RawCause\":\"Error 1062: Duplicate entry '12' for key 'PRIMARY'\"}"][2021/12/03 16:54:45.961 +08:00] [WARN] [task_checker.go:390] ["task can't auto resume"] [component="task checker"] [task=two_tidb_slave]…………
[tidb@tidb1 ~]$ tiup dmctl -master-addr ***.**.***.134:8261 stop-task task3637.yaml[tidb@tidb1 ~]$ tiup dmctl -master-addr ***.**.***.134:8261 start-task task3637.yaml
[tidb@tidb1 ~]$ tiup dmctl --master-addr ***.**.***.134:8261 query-status two_tidb_slave
情况2:
全量导入数据之前,该主键数据已经存在于下游数据库中。
情况3:
由于位点信息被清理导致 sql 文件被重复导入(未重现,需要根据情况进行判断,BUG情况需要提交AskTUG专家进行分析)。
1)利用 tidb API 查看主键冲突的行的 mvcc 版本,以此来确认该行数据插入数据库的时间
curl http://{TiDBIP}:1**80/mvcc/key/{db}/{table}/{handle}
select _tidb_rowid from xxx where trade_no=‘190606LI8OODRTZA5XX1’;curl http://{TiDBIP}:1**80/mvcc/key/{db}/{table}/{_tidb_rowid}


2)在 dm_meta 查询 min(create_time) 来获得 load 第一个文件时的时间,可以认为是 全量迁移阶段的开始时间。

3)在 dm_meta 中查看 xxx_loadder_checkpoint 表查看该文件 test.sbtest5.000000005.sql 的详细信息!

4)从 dm-worker 中 grep 查看该主键所在的 .sql 文件出现的时间以及次数

本文作者:陈聪
本文来源:IT那活儿(上海新炬王翦团队)

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




