Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: tidb 自增id 冲突
[TiDB Usage Environment] Production Environment
[TiDB Version] tidb-vv.5.4.3
[Reproduction Path] Normal business insert
[Encountered Problem]
Business insert data reports primary key conflict, restarting tidb-server alleviates the issue, but after a while, the primary key conflict reappears.
Table Structure Information:
Due to the need to synchronize data to downstream Hive via CDC, using auto_random can easily cause field overflow issues in Hive, so auto-increment ID is used.
MySQL [dcflow]> show create table tblSeaSearch\G
*************************** 1. row ***************************
Table: tblSeaSearch
Create Table: CREATE TABLE `tblSeaSearch` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`eid` varchar(32) DEFAULT NULL,
`flowid` bigint(20) DEFAULT NULL,
`dataid` bigint(20) DEFAULT NULL,
`content` mediumtext DEFAULT NULL,
`nshead` varchar(128) DEFAULT NULL,
`alvl` int(11) DEFAULT '0',
`alen` int(11) DEFAULT '0',
`deleted` int(10) NOT NULL DEFAULT '0',
`ctime` int(10) NOT NULL DEFAULT '0',
`utime` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
KEY `ctime` (`ctime`),
KEY `eid` (`eid`),
KEY `utime` (`utime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=41110159
TiDB Log Information
[2022/11/15 14:48:07.749 +08:00] [INFO] [conn.go:1121] ["command dispatched failed"] [conn=1245901] [connInfo="id:1245901, addr:10.32.11.109:35788 status:10, collation:utf8mb4_general_ci, user:dcflow_app"] [command=Execute] [status="inTxn:0, autocommit:1"] [sql="INSERT INTO `tblSeaSearch` (`flowid`,`dataid`) VALUES (?,?) [arguments: (0, 30001)]"] [txn_mode=PESSIMISTIC] [err="INSERT INTO `tblSeaSearch` (`flowid`,`dataid`) VALUES (?,?) [arguments: (0, 30001)]: [kv:1062]Duplicate entry '40376465' for key 'PRIMARY'"]
Monitoring Information