Skip to content

Got duplicate entry error for auto increment column #53016

@guo-shaoge

Description

@guo-shaoge

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. apply tidb code, check detail code from when leader switch, autoid service does not reset the map #52600. So we can reassign auto_id service leader
  2. setup tidb cluster(2 tidb/1 tikv/1 pd)
  3. By running following command to make sure auto_id leader is in tidb-0(10080). (command result is 'not owner')
curl http://127.0.0.1:10081/autoid/leader/resign
result: not owner
  1. run the following sql to create table:
create table t (id int primary key auto_increment, k int) auto_id_cache = 1;
insert into t (k) values (1);
insert into t (k) values (2);
insert into t (k) values (3);
insert into t (k) values (5);
  1. reassign autoid leader to tidb-1(10081). (the result of the command should be success)
curl http://127.0.0.1:10080/autoid/leader/resign
  1. run the following sqls to insert again:
insert into t (k) values (6);
insert into t (k) values (7);
insert into t (k) values (8);
  1. tiup restart tidb-1(10081)
  2. tiup restart tidb-0(10080)
  3. run the following sqls to insert 4000 lines: t.txt
source /home/guojiangtao/work/tidb/t.txt;

2. What did you expect to see? (Required)

insert runs ok

3. What did you see instead (Required)

img_v3_02af_d95c0cd9-5ec4-418f-a411-b58310ecf73g

4. What is your TiDB version? (Required)

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                           |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.1.0-alpha-1-g42f4a3133d
Edition: Community
Git Commit Hash: 42f4a3133d8cc5309a5fa4dd7c92a2a1cfa3cbca
Git Branch: debug_autoid
UTC Build Time: 2024-05-01 06:19:47
GoVersion: go1.21.0
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.009 sec)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions