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

DROP PARTITION has an anomaly during DELETE ONLY state, which looks like PK violation. #55888

Open
mjonss opened this issue Sep 5, 2024 · 2 comments · May be fixed by #56082
Open

DROP PARTITION has an anomaly during DELETE ONLY state, which looks like PK violation. #55888

mjonss opened this issue Sep 5, 2024 · 2 comments · May be fixed by #56082
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 affects-7.5 affects-8.1 impact/inconsistency incorrect/inconsistency/inconsistent severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@mjonss
Copy link
Contributor

mjonss commented Sep 5, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Repeatable test case here. Check out the branch, make failpoint-enable then run the test TestMultiSchemaDropPartition.

It looks like this in a multi domain (tidb node) scenario:

-- DDL Owner node
create table t (a int primary key, b varchar(255)) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200));
insert into t values (1,1);
-- Schema version v0
alter table t drop partition p0;
-- new client1 seeing v0+1 StateDeleteOnly, most likely in the DDL Owner domain/node
-- valid, since the table does no longer contain partition p0
insert into t values (1,1);
-- in the other domain, client 2, still in v0, still seeing partition p0
-- looks like PK violation!!!
select * from t; -- "1 1", "1 1"
-- Original row
select * from t partition (p0); -- "1 1"
-- This is not consistent with the view of the partition definitions!
-- sees new row from client1
select * from t partition (p1); -- "1 1"

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

This is not completely well defined with TiDB's DDL model, since it allows two schema versions with the same data.
But the most consistent view would probably be to not allow duplicate keys when the dropping partitions still can be used.
How to handle the anomaly that rows can exists in an overlapping partition (this case p1, when p0 is being dropped) is harder to define, since it would also be strange to not allow inserts/updates in p1 (that may match dropped p0) by client1 during StateDeleteOnly just because it may overlap with possible sessions seeing v0 schema versions

3. What did you see instead (Required)

See repeatable test case.
Duplicate rows and rows in p1 that matches the partition definition of p0 in client2.

4. What is your TiDB version? (Required)

b8a37f2 based on current master 9c7f4eb
i.e. v8.4.0-alpha something

@mjonss mjonss added the type/bug The issue is confirmed as a bug. label Sep 5, 2024
@jebter jebter added severity/critical component/ddl This issue is related to DDL of TiDB. labels Sep 10, 2024
@jebter jebter added the impact/inconsistency incorrect/inconsistency/inconsistent label Sep 10, 2024
@Defined2014
Copy link
Contributor

Defined2014 commented Sep 11, 2024

We should prohibit insert data in the StateDeleteOnly.

@mjonss
Copy link
Contributor Author

mjonss commented Sep 16, 2024

It is most likely affecting 7.1 and earlier as well, but it is harder to test.

@mjonss mjonss added affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 and removed 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 Sep 16, 2024
@jebter jebter added sig/sql-infra SIG: SQL Infra and removed component/ddl This issue is related to DDL of TiDB. labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 affects-7.5 affects-8.1 impact/inconsistency incorrect/inconsistency/inconsistent severity/critical 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.

3 participants