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

cdc: EXCHANGE PARTITION dropped the WITHOUT VALIDATION clause #10859

Closed
kennytm opened this issue Mar 28, 2024 · 3 comments · Fixed by #10867
Closed

cdc: EXCHANGE PARTITION dropped the WITHOUT VALIDATION clause #10859

kennytm opened this issue Mar 28, 2024 · 3 comments · Fixed by #10867
Assignees
Labels
affects-6.5 affects-7.1 affects-7.5 affects-8.0 area/ticdc Issues or PRs related to TiCDC. found/customer Customers have encountered this bug. found/gs severity/major This is a major bug. type/bug This is a bug.

Comments

@kennytm
Copy link
Contributor

kennytm commented Mar 28, 2024

What did you do?

create a TiDB → TiCDC → TiDB changefeed and execute the following in upstream:

USE test;

CREATE TABLE employees (
    id INT NOT NULL ,
    store_id INT NOT NULL primary key
) PARTITION BY RANGE (store_id) (
    PARTITION p0 VALUES LESS THAN (6),
    PARTITION p1 VALUES LESS THAN (11),
    PARTITION p2 VALUES LESS THAN (16),
    PARTITION p3 VALUES LESS THAN (21)
);

CREATE TABLE employees_temp (
    id INT NOT NULL ,
    store_id INT NOT NULL primary key
);

insert into employees values(1,1);
insert into employees values(8,8);
insert into employees_temp values(16,8);
insert into employees_temp values(17,17);
ALTER TABLE employees EXCHANGE PARTITION p0 WITH TABLE employees_temp without VALIDATION;

What did you expect to see?

The DDL is sync to the downstream TiDB correctly.

What did you see instead?

The changefeed is stuck. TiCDC has rewritten the DDL which stripped out the WITHOUT VALIDATION option

ALTER TABLE `test`.`employees` EXCHANGE PARTITION `p0` WITH TABLE `test`.`employees_temp`

which caused the [ddl:1737]Found a row that does not match the partition unretryable error

Versions of the cluster

Upstream TiDB cluster version (execute SELECT tidb_version(); in a MySQL client):

v6.5.8

Upstream TiKV version (execute tikv-server --version):

v6.5.8

TiCDC version (execute cdc version):

v6.5.8
@kennytm
Copy link
Contributor Author

kennytm commented Mar 28, 2024

The DDL is constructed in:

tiflow/cdc/model/sink.go

Lines 1052 to 1063 in c178273

case model.ActionExchangeTablePartition:
// Parse idx of partition name from query.
upperQuery := strings.ToUpper(job.Query)
idx1 := strings.Index(upperQuery, "EXCHANGE PARTITION") + len("EXCHANGE PARTITION")
idx2 := strings.Index(upperQuery, "WITH TABLE")
// Note that partition name should be parsed from original query, not the upperQuery.
partName := strings.TrimSpace(job.Query[idx1:idx2])
// The tableInfo is the partition table, preTableInfo is non partition table.
d.Query = fmt.Sprintf("ALTER TABLE `%s`.`%s` EXCHANGE PARTITION `%s` WITH TABLE `%s`.`%s`",
tableInfo.TableName.Schema, tableInfo.TableName.Table, partName,
preTableInfo.TableName.Schema, preTableInfo.TableName.Table)

which did not check if the query contained the "WITHOUT VALIDATION" clause

I also question the method to extract the part name from the SQL. Because running this:

ALTER TABLE employees EXCHANGE   /*lol*/   PARTITION p0 WITH    /*rofl*/   TABLE employees_temp without VALIDATION;

will immediately crash TiCDC.

@fubinzh
Copy link

fubinzh commented Mar 29, 2024

/severity major

ti-chi-bot bot pushed a commit that referenced this issue Apr 1, 2024
Question and Bug Reports automation moved this from Need Triage to Done Apr 1, 2024
ti-chi-bot bot pushed a commit that referenced this issue Apr 2, 2024
ti-chi-bot bot pushed a commit that referenced this issue Apr 11, 2024
ti-chi-bot bot pushed a commit that referenced this issue May 8, 2024
@seiya-annie
Copy link

/found customer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 affects-7.1 affects-7.5 affects-8.0 area/ticdc Issues or PRs related to TiCDC. found/customer Customers have encountered this bug. found/gs severity/major This is a major bug. type/bug This is a bug.
4 participants