pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://tidbcloud.com/free-trial
https://pingcap.com
Apache License 2.0
36.27k stars 5.72k forks source link

Got duplicate entry error for auto increment column #53016

Closed guo-shaoge closed 1 week ago

guo-shaoge commented 2 weeks ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. apply tidb code, check detail code from https://github.com/pingcap/tidb/issues/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
  4. 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);
  5. 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
  6. 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);
  7. tiup restart tidb-1(10081)
  8. tiup restart tidb-0(10080)
  9. 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)
tiancaiamao commented 1 week ago

Duplicated with https://github.com/pingcap/tidb/issues/52600

Are you testing with 8.1? It has not merge the cherry-pick yet https://github.com/pingcap/tidb/pull/53000 @guo-shaoge

guo-shaoge commented 1 week ago

Duplicated with #52600

Are you testing with 8.1? It has not merge the cherry-pick yet #53000 @guo-shaoge

No, I tested it with v7.5.1.