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

snapshot information schema may be wrong if switching schema cache v1/v2 #54926

Closed
wjhuang2016 opened this issue Jul 26, 2024 · 1 comment · Fixed by #54966
Closed

snapshot information schema may be wrong if switching schema cache v1/v2 #54926

wjhuang2016 opened this issue Jul 26, 2024 · 1 comment · Fixed by #54966
Labels

Comments

@wjhuang2016
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

img_v3_02d5_6223c4c8-2bf2-46a0-bb04-b6b6069458eg
Modify code and run test

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

test passes

3. What did you see instead (Required)

test fails

4. What is your TiDB version? (Required)

master

@tiancaiamao
Copy link
Contributor

OK, this bug not only exist in v1 v2 switch.
It exists even only v1 is used.

Here is another way to reproduce:

Start tidb:

tiup playground --mode tikv-slim
./bin/tidb-server -status 10080 -P 4000 -store=tikv -path=127.0.0.1:2379

Create table and prepare different snapshot checkpoint:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2024-07-26 19:36:13 |
+---------------------+
1 row in set (0.00 sec)

mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table t (id int);
Query OK, 0 rows affected (0.04 sec)

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2024-07-26 19:37:46 |
+---------------------+
1 row in set (0.00 sec)

===============

mysql> drop table t;
Query OK, 0 rows affected (0.08 sec)

mysql> create table t (a int, b int);
Query OK, 0 rows affected (0.04 sec)

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2024-07-26 19:38:11 |
+---------------------+
1 row in set (0.00 sec)

==================


mysql> drop table t;
Query OK, 0 rows affected (0.08 sec)

mysql> create table t (a int, b int, c int);
Query OK, 0 rows affected (0.04 sec)

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2024-07-26 19:38:38 |
+---------------------+
1 row in set (0.00 sec)

Restart tidb:

Ctrl+C
./bin/tidb-server -status 10080 -P 4000 -store=tikv -path=127.0.0.1:2379

Environment prepare finish, now test!

mysql -h 127.0.0.1 -u root -P 4000

mysql> show create table t;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                      |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `a` int(11) DEFAULT NULL,
  `b` int(11) DEFAULT NULL,
  `c` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)               <====   the latest schema, everything goes well

mysql> set @@tidb_snapshot = '2024-07-26 19:37:46';
Query OK, 0 rows affected (0.01 sec)

mysql> show create table t;
+-------+------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                               |
+-------+------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)                        <====    back to oldest snapshot, just after the first create table, OK

mysql> set @@tidb_snapshot = '2024-07-26 19:38:12';
Query OK, 0 rows affected (0.01 sec)

mysql> show create table t;
+-------+------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                               |
+-------+------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)                         <==   switch again to sometime between the oldest and latest, now buggy!
                                                            <==   this time the schema should be `create table t (a int, b int)`   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants