-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.This bug affects the 8.1.x(LTS) versions.severity/majorsig/sql-infraSIG: SQL InfraSIG: SQL Infratype/bugThe issue is confirmed as a bug.The issue is confirmed as a bug.
Description
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
Line 563 in b4c8749
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
tidb/pkg/autoid_service/autoid.go
Line 385 in b4c8749
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)
Metadata
Metadata
Assignees
Labels
affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.This bug affects the 8.1.x(LTS) versions.severity/majorsig/sql-infraSIG: SQL InfraSIG: SQL Infratype/bugThe issue is confirmed as a bug.The issue is confirmed as a bug.