1、版本:
tidb-lightning:
Release Version: v4.0.0-rc.2
Git Commit Hash: 391db4a233a870fc2044494caa770da791f49734
tikv-importer:
TiKV Importer 4.0.0
tidb:
TiDB Version: v4.0.0
2、表结构(7亿多数据)
源表中用auto_random属性作为主键
3、问题:
导入数据完成之后,程序插入数据到表中,频繁报主键冲突
1、版本:
tidb-lightning:
Release Version: v4.0.0-rc.2
Git Commit Hash: 391db4a233a870fc2044494caa770da791f49734
tikv-importer:
TiKV Importer 4.0.0
tidb:
TiDB Version: v4.0.0
2、表结构(7亿多数据)
源表中用auto_random属性作为主键
3、问题:
导入数据完成之后,程序插入数据到表中,频繁报主键冲突
tidb-lightning 版本与其他组件版本不一致,官方要求使用相同版本,避免不必要的问题。确认下数据是否已经正常导入
针对 2. 的意思,你建议指定该列的值:
create table t(id bigint primary key auto_random, name char(20));
insert into t values(default, ‘jack’);
insert into t(name) values(‘may’);
1、表结构:
CREATE TABLE `click` (
`id` bigint(20) unsigned NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
`log_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`app_group_id` varchar(64) NOT NULL DEFAULT '' COMMENT 'tk_appkey',
`log_type` varchar(20) NOT NULL DEFAULT '',
`device_type` varchar(10) NOT NULL DEFAULT 'unknown' ,
`surl` varchar(32) NOT NULL DEFAULT '',
`idfa_md5` varchar(32) NOT NULL DEFAULT '',
`mac` varchar(32) NOT NULL DEFAULT '' ,
`mac_md5` varchar(32) NOT NULL DEFAULT '' ,
`ip` varchar(128) NOT NULL DEFAULT '' ,
`csite` varchar(32) NOT NULL DEFAULT '' ,
`ctype` varchar(32) NOT NULL DEFAULT '' ,
`aname` varchar(400) NOT NULL DEFAULT '' ,
`group_id` varchar(64) NOT NULL DEFAULT '' ,
`cid` varchar(64) NOT NULL DEFAULT '' ,
`aid` varchar(64) NOT NULL DEFAULT '' ,
`click_date` int(11) NOT NULL DEFAULT 0,
`log_db_date` int(11) NOT NULL DEFAULT 0 ,
`click_time` timestamp NULL DEFAULT NULL ,
`click_ts` int(11) NOT NULL DEFAULT 0 ,
`click_hour` char(2) NOT NULL DEFAULT '',
`advertiser_id` varchar(64) NOT NULL ,
`ua` varchar(400) NOT NULL COMMENT 'User Agent',
`ua_os` varchar(32) NOT NULL ,
`ua_browser` varchar(64) NOT NULL ,
`platform_device_type` varchar(10) NOT NULL ,
PRIMARY KEY (`id`),
KEY `idx_app_group_id` (`app_group_id`),
KEY `idx_idfa_md5` (`idfa_md5`),
KEY `idx_click_ts` (`click_ts`),
KEY `idx_surl` (`surl`),
KEY `idx_log_db_date` (`log_db_date`),
KEY `idx_ip` (`ip`),
KEY `idx_ua_os` (`ua_os`),
KEY `idx_ua_browser` (`ua_browser`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
2、insert语句:
"INSERT INTO `click` (`log_time`, `app_group_id`, `log_type`, `device_type`,`surl`,`idfa_md5`,`mac`,`mac_md5`,`ip`,`csite`, `ctype`,`aname`,`group_id`,`cid`,`aid`,`click_date`,`log_db_date`,`click_time`,`click_ts`,`click_hour`,`advertiser_id`,`ua`,`ua_os`,`ua_browser`,`platform_device_type`) VALUES ('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', '75oWB','eCt7247NwFBKwWq041FPIj4eTkEgi9SZ', '', '', '210.39.219.227', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45001', '13.2.2', 'v61', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', '3JpVI','JXh5VbJmErQLE8Ro09gcaUhFbBcX9bm3', '', '', '139.198.201.11', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45002', '13.2.2', 'v69', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'vnyeL','19yRYZIdWAlCUYgWQricH08Oi1hDORet', '', '', '61.235.15.170', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45003', '12.1.3', 'v69', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'JxjPp','CQRLxs4corFbZjEsTzUPLGoMmkdPyWpD', '', '', '106.80.189.40', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45004', '12.1.3', 'v69', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'd2msZ','U185VBCZQKru7y3a1Q1GJikn7SS3gdR1', '', '', '61.235.82.116', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45005', '12.1.3', 'v58', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'oMmdO','wDaB0s8Pj6fgUMG9ONDcvU5t9pt0iweR', '', '', '171.10.117.87', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45006', '13.2.2', 'v61', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'RWaRY','4K0oe7cIre5eYx1sgcxzJO9WQCgk9wFG', '', '', '123.235.203.104', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45007', '12.1.3', 'v69', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'GPqhL','ij5bx3GZJU1Ykqv9WPfSlMQ8TciB1LUQ', '', '', '139.207.79.171', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45008', '13.2.2', 'v58', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'bOCE4','3WZjsgEv2vtFq6H9KGzmMmGeeXEn54IN', '', '', '121.77.234.108', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45009', '13.1.1', 'v61', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'oDV2C','p8W7X2DFgu1jteSwPLSNzIfa0c74DnnQ', '', '', '222.31.195.217', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45010', '13.1.1', 'v69', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'xVnnt','3Kty8MCStsoGnXUvW00yVJOQE66laulv', '', '', '210.34.152.203', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45011', '7.0.2', 'v58', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'qUMU5','OoiE5SffRTX6m2jrUWXu8hHrZvRNnc0T', '', '', '123.233.91.108', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45012', '13.2.2', 'v61', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', '4bdty','lZX4RlNUMWkh0nWuEKnsACF50yy8I6QF', '', '', '139.213.95.178', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45013', '13.2.2', 'v66', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 'tkio', 'ios', 'HoNTJ','EMxztxBWRPk2itPiGeDUZGX5vneDCHek', '', '', '222.23.200.95', '','', '', '', '', '',20200617, 20200617, '2020-06-17 10:03:35.0', 1592359415, 10,'', '45014', '7.0.2', 'v61', 'ios'),('2020-06-17 10:03:35.0', '25071374c3670e7e7192ea25caf2c7d0', 't"(len :795253);
3、程序是通过nginx代理来连接tidb-server
4、建议指定该列值,是说id列值要自己设置?
感谢你的反馈,
不,你的用法是正确的,不指定 id 列,auto_random 自己生成。
@户口舟亢 感谢回复
1、集群topology
TiDB Version: v4.0.0
ID Role Host Ports OS/Arch Status Data Dir Deploy Dir
-- ---- ---- ----- ------- ------ -------- ----------
10.59.111.56:9093 alertmanager 10.59.111.56 9093/9094 linux/x86_64 Up /data/tidb_data/alertmanager-9093 /data/tidb_deploy/alertmanager-9093
10.59.111.56:3000 grafana 10.59.111.56 3000 linux/x86_64 Up - /data/tidb_deploy/grafana-3000
10.59.111.152:2379 pd 10.59.111.152 2379/2380 linux/x86_64 Healthy|UI /data/tidb_data/pd-2379 /data/tidb_deploy/pd-2379
10.59.111.43:2379 pd 10.59.111.43 2379/2380 linux/x86_64 Healthy|L /data/tidb_data/pd-2379 /data/tidb_deploy/pd-2379
10.59.111.91:2379 pd 10.59.111.91 2379/2380 linux/x86_64 Healthy /data/tidb_data/pd-2379 /data/tidb_deploy/pd-2379
10.59.111.56:9090 prometheus 10.59.111.56 9090 linux/x86_64 Up /data/tidb_data/prometheus-9090 /data/tidb_deploy/prometheus-9090
10.59.111.152:4000 tidb 10.59.111.152 4000/10080 linux/x86_64 Up - /data/tidb_deploy/tidb-4000
10.59.111.43:4000 tidb 10.59.111.43 4000/10080 linux/x86_64 Up - /data/tidb_deploy/tidb-4000
10.59.111.91:4000 tidb 10.59.111.91 4000/10080 linux/x86_64 Up - /data/tidb_deploy/tidb-4000
10.59.111.48:9000 tiflash 10.59.111.48 9000/8123/3930/20170/20292/8234 linux/x86_64 Up /data/tidb_data/tiflash-9000 /data/tidb_deploy/tiflash-9000
10.59.111.140:20160 tikv 10.59.111.140 20160/20180 linux/x86_64 Up /data/tidb_data/tikv-20160 /data/tidb_deploy/tikv-20160
10.59.111.165:20160 tikv 10.59.111.165 20160/20180 linux/x86_64 Up /data/tidb_data/tikv-20160 /data/tidb_deploy/tikv-20160
10.59.111.168:20160 tikv 10.59.111.168 20160/20180 linux/x86_64 Up /data/tidb_data/tikv-20160 /data/tidb_deploy/tikv-20160
2、tidb.log
tidb.log.tar.gz (4.1 MB)
3、我们的解决办法:
on duplicate key update
nginx是反向代理,客户端是连接到nginx,nginx再连接到tidb-server,相当于是负载均衡
这种模式会有什么问题么?
nginx 是可以用于 tidb 前端负载均衡的,辛苦看下私信,可能需要提供更多的信息帮助排查。
你好,问题是说:
在源 TiDB 集群中使用 auto_random 作为主键,对源 TiDB 集群进行备份然后使用 Lightening 导入到新的 TiDB 集群,把业务逻辑切换到导入之后的 TiDB 集群,发现报主键冲突这样么?
1、使用mydumper把表导出(用auto_random作为主键)
2、使用tidb-lighting和tikv-importer,把表导入到新的tidb集群中
3、业务在新的tidb集群对这张表进行插入,频繁发生主键冲突错误
问题原因是
4.0.0-rc.2 的 lightinig 不支持 auto_random
v4.0.2 会支持
目前的情况需要手动 rebase 一下
这个问题看起来已经在 github 上面提过了
https://github.com/pingcap/tidb-lightning/issues/333
我看日志里面的表名和 github issue 里面的表名是一样的
目前解决方案是:
SELECT max(id & ((1 << (63 - 5)) - 1)) FROM spl_click_ios_test;
alter table spl_click_ios_test auto_random_base=?;
ok,pr 中已经看到了。感谢分享。
此话题已在最后回复的 1 分钟后被自动关闭。不再允许新回复。