Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate entry when insert into a recovered table with auto_id_cache=1 #52680

Closed
D3Hunter opened this issue Apr 17, 2024 · 0 comments · Fixed by #52761
Closed

Duplicate entry when insert into a recovered table with auto_id_cache=1 #52680

D3Hunter opened this issue Apr 17, 2024 · 0 comments · Fixed by #52761

Comments

@D3Hunter
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  • start a cluster with 1 tidb to ease reproduce
mysql> create table tt(id bigint primary key auto_increment) auto_id_cache=1;
Query OK, 0 rows affected (0.10 sec)

mysql> insert into tt values(default),(default);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from tt;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)
  • restart the tidb, so id cache is flushed
mysql> drop table tt;
Query OK, 0 rows affected (0.28 sec)

mysql> select * from tt;
ERROR 1146 (42S02): Table 'ttt.tt' doesn't exist
mysql> recover table tt;
Query OK, 0 rows affected (0.14 sec)

mysql> select * from tt;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)

mysql> insert into tt values(default);
ERROR 1062 (23000): Duplicate entry '1' for key 'tt.PRIMARY'

the reason is we drop the IID key when drop table, but didn't recover it when recover table

err = t.CreateTableAndSetAutoID(recoverInfo.SchemaID, recoverInfo.OldSchemaName, tableInfo, recoverInfo.AutoIDs.RowID, recoverInfo.AutoIDs.RandomID)

also when drop table we didn't invalid the cached id in autoid_service, when this tidb shutdown it will force rebase the id of the droped table, and cause meta inconsistent

err := v.forceRebase(context.Background(), s.store, k.dbID, k.tblID, v.base, v.isUnsigned)

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

success

3. What did you see instead (Required)

fail

4. What is your TiDB version? (Required)

@D3Hunter D3Hunter added the type/bug This issue is a bug. label Apr 17, 2024
@tiancaiamao tiancaiamao self-assigned this Apr 17, 2024
@tiancaiamao tiancaiamao removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 labels Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants