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

Table gone after concurrent EXCHANGE PARTITION #45920

Closed
mjonss opened this issue Aug 8, 2023 · 2 comments · Fixed by #45877
Closed

Table gone after concurrent EXCHANGE PARTITION #45920

mjonss opened this issue Aug 8, 2023 · 2 comments · Fixed by #45877
Assignees
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. component/tablepartition This issue is related to Table Partition of TiDB. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@mjonss
Copy link
Contributor

mjonss commented Aug 8, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

tidb1> create table t (a int);
tidb1> create table tp (a int) partition by hash (a) partitions 3;
tidb1> create table t2 (a int);

tidb2> begin;
tidb2> insert into tp values (1);

tidb1> alter table tp exchange partition p0 with table t;

tidb3> alter table tp exchange partition p0 with table t2; -- fails error 8038, information schema changed

tidb2> rollback;

tidb1> select * from t2; -- Fails: ERROR 1146 (42S02): Table 'test.t2' doesn't exist

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

Failure with out the table removed

3. What did you see instead (Required)

Failure and table t2 no longer found.

4. What is your TiDB version? (Required)

tidb_version(): Release Version: v7.4.0-alpha
Edition: Community
Git Commit Hash: d590ccb14e2e36610f7a1313ed75904088b7d84e
Git Branch: heads/refs/tags/v7.4.0-alpha
UTC Build Time: 2023-08-07 14:24:53
GoVersion: go1.20.7
Race Enabled: false
Check Table Before Drop: false
Store: tikv
@mjonss mjonss added type/bug The issue is confirmed as a bug. component/tablepartition This issue is related to Table Partition of TiDB. labels Aug 8, 2023
@mjonss mjonss self-assigned this Aug 8, 2023
@mjonss
Copy link
Contributor Author

mjonss commented Aug 8, 2023

The issue seems to be that the partitionID is set in the ddl client session (ddl_api.go) and then is used as the new tableID when applying the diff. This works for the first alter, but for the second alter, the given partitionID (same as the first one) is then used in applyCreateTable. So the second exchange partition will drop the the 't2' table, but when it will recreate it with the new tableID, it has already been swapped with 't', so it gets the first table instead of the partition/partitioned table, since it has already exchanged with the partition. So later when the second exchange partition tries to validate the rows it fails, since it cannot find any 't2' table (and information_schema.tables shows two 't' tables with the same table_id...).

@mjonss
Copy link
Contributor Author

mjonss commented Aug 8, 2023

Since it is only gone from the table cache, a restart will make the table appear again...

@ti-chi-bot ti-chi-bot bot added may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Aug 9, 2023
@mjonss mjonss added the affects-7.1 This bug affects the 7.1.x(LTS) versions. label Aug 10, 2023
@mjonss mjonss added affects-6.5 This bug affects the 6.5.x(LTS) versions. and removed may-affects-6.5 may-affects-6.1 may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. labels Aug 10, 2023
ti-chi-bot bot pushed a commit that referenced this issue Aug 10, 2023
ti-chi-bot bot pushed a commit that referenced this issue Sep 11, 2023
YangKeao pushed a commit to YangKeao/tidb that referenced this issue Sep 12, 2023
@jayl1e jayl1e mentioned this issue Sep 21, 2023
11 tasks
ti-chi-bot bot pushed a commit that referenced this issue Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. component/tablepartition This issue is related to Table Partition of TiDB. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants