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

Support ALTER TABLE t REORGANIZE PARTITION #8114

Merged
merged 9 commits into from
Mar 16, 2023
3 changes: 2 additions & 1 deletion cdc/entry/schema/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ func (s *Snapshot) DoHandleDDL(job *timodel.Job) error {
}
case timodel.ActionTruncateTablePartition,
timodel.ActionAddTablePartition,
timodel.ActionDropTablePartition:
timodel.ActionDropTablePartition,
timodel.ActionReorganizePartition:
err := s.inner.updatePartition(getWrapTableInfo(job), job.BinlogInfo.FinishedTS)
if err != nil {
return errors.Trace(err)
Expand Down
2 changes: 2 additions & 0 deletions cdc/entry/schema_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,8 @@ func TestSchemaStorage(t *testing.T) {
"alter table test_ddl2.simple_test1 add primary key pk(id)", // ActionAddPrimaryKey
"ALTER TABLE test_ddl2.simple_test1 ALTER id SET DEFAULT 18", // ActionSetDefaultValue
"ALTER TABLE test_ddl2.simple_test1 CHARACTER SET = utf8mb4", // ActionModifyTableCharsetAndCollate

"ALTER TABLE test_ddl2.employees REORGANIZE PARTITION p3 INTO (PARTITION p2 VALUES LESS THAN (15), PARTITION p3 VALUES LESS THAN (20))", // ActionReorganizePartition
// "recover table test_ddl2.employees", // ActionRecoverTable this ddl can't work on mock tikv

"DROP TABLE test_ddl2.employees",
Expand Down
1 change: 1 addition & 0 deletions pkg/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var allowDDLList = []timodel.ActionType{
timodel.ActionAlterIndexVisibility,
timodel.ActionMultiSchemaChange,
timodel.ActionExchangeTablePartition,
timodel.ActionReorganizePartition,
timodel.ActionAlterTTLInfo,
timodel.ActionAlterTTLRemove,
}
Expand Down
1 change: 1 addition & 0 deletions pkg/filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func TestShouldDiscardDDL(t *testing.T) {
require.False(t, filter.ShouldDiscardDDL(timodel.ActionAlterIndexVisibility, "", ""))
require.False(t, filter.ShouldDiscardDDL(timodel.ActionMultiSchemaChange, "", ""))
require.False(t, filter.ShouldDiscardDDL(timodel.ActionExchangeTablePartition, "", ""))
require.False(t, filter.ShouldDiscardDDL(timodel.ActionReorganizePartition, "", ""))

// Discard sequence DDL.
require.True(t, filter.ShouldDiscardDDL(timodel.ActionAddForeignKey, "", ""))
Expand Down
1 change: 1 addition & 0 deletions pkg/filter/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestDDLToEventType(t *testing.T) {
{"Alter table test.t1 drop partition t11", timodel.ActionDropTablePartition, bf.DropTablePartition, nil},
{"Alter table test.t1 add partition (partition p3 values less than (2002))", timodel.ActionDropTablePartition, bf.DropTablePartition, nil},
{"Alter table test.t1 truncate partition t11", timodel.ActionDropTablePartition, bf.DropTablePartition, nil},
{"Alter table test.t1 reorganize partition p11 into (partition p1 values less than (10), partition p2 values less than (20))", timodel.ActionReorganizePartition, bf.AlterTable, nil},
{"alter table add i", timodel.ActionAddIndex, bf.NullEvent, cerror.ErrConvertDDLToEventTypeFailed},
}
p := parser.New()
Expand Down
2 changes: 1 addition & 1 deletion pkg/sink/codec/canal/canal_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func convertDdlEventType(e *model.DDLEvent) canal.EventType {
case mm.ActionAddColumn, mm.ActionDropColumn, mm.ActionModifyColumn, mm.ActionRebaseAutoID,
mm.ActionSetDefaultValue, mm.ActionModifyTableComment, mm.ActionRenameIndex, mm.ActionAddTablePartition,
mm.ActionDropTablePartition, mm.ActionModifyTableCharsetAndCollate, mm.ActionTruncateTablePartition,
mm.ActionAlterIndexVisibility, mm.ActionMultiSchemaChange,
mm.ActionAlterIndexVisibility, mm.ActionMultiSchemaChange, mm.ActionReorganizePartition,
// AddColumns and DropColumns are removed in TiDB v6.2.0, see https://github.com/pingcap/tidb/pull/35862.
mm.ActionAddColumns, mm.ActionDropColumns:
return canal.EventType_ALTER
Expand Down
3 changes: 3 additions & 0 deletions tests/integration_tests/partition_table/data/prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ ALTER TABLE t1 EXCHANGE PARTITION p3 WITH TABLE t2;
insert into t2 values (100),(101),(102),(103),(104),(105); /*these values will be replicated to in downstream t2*/
insert into t1 values (25),(29); /*these values will be replicated to in downstream t1.p3*/

ALTER TABLE t1 REORGANIZE PARTITION p0,p2 INTO (PARTITION p0 VALUES LESS THAN (5), PARTITION p1 VALUES LESS THAN (10), PARTITION p2 VALUES LESS THAN (21));
ALTER TABLE t1 REORGANIZE PARTITION p2,p3,p4 INTO (PARTITION p2 VALUES LESS THAN (20), PARTITION p3 VALUES LESS THAN (26), PARTITION p4 VALUES LESS THAN (35), PARTITION pMax VALUES LESS THAN (MAXVALUE));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some insert querys below line 29 and line 30 to examine TiCDC can replicate data correctly after these DDL. thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asddongmen I have added some dml after each of the two DML statements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you ~! LGTM

create table finish_mark (a int primary key);