diff --git a/cdc/entry/schema/snapshot.go b/cdc/entry/schema/snapshot.go index eb7c9eb394a..2f4991eb0ca 100644 --- a/cdc/entry/schema/snapshot.go +++ b/cdc/entry/schema/snapshot.go @@ -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) diff --git a/cdc/entry/schema_storage_test.go b/cdc/entry/schema_storage_test.go index 3a283a462a5..8bf0faf7ca0 100644 --- a/cdc/entry/schema_storage_test.go +++ b/cdc/entry/schema_storage_test.go @@ -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", diff --git a/pkg/filter/filter.go b/pkg/filter/filter.go index 27a90d42af4..cf186cceeda 100644 --- a/pkg/filter/filter.go +++ b/pkg/filter/filter.go @@ -54,6 +54,7 @@ var allowDDLList = []timodel.ActionType{ timodel.ActionAlterIndexVisibility, timodel.ActionMultiSchemaChange, timodel.ActionExchangeTablePartition, + timodel.ActionReorganizePartition, timodel.ActionAlterTTLInfo, timodel.ActionAlterTTLRemove, } diff --git a/pkg/filter/filter_test.go b/pkg/filter/filter_test.go index f449cc2be69..e4c53b35e68 100644 --- a/pkg/filter/filter_test.go +++ b/pkg/filter/filter_test.go @@ -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, "", "")) diff --git a/pkg/filter/utils_test.go b/pkg/filter/utils_test.go index 824c40731d6..6bceab98604 100644 --- a/pkg/filter/utils_test.go +++ b/pkg/filter/utils_test.go @@ -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() diff --git a/pkg/sink/codec/canal/canal_entry.go b/pkg/sink/codec/canal/canal_entry.go index 25e6506e1ab..809074dc72c 100644 --- a/pkg/sink/codec/canal/canal_entry.go +++ b/pkg/sink/codec/canal/canal_entry.go @@ -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 diff --git a/tests/integration_tests/partition_table/data/prepare.sql b/tests/integration_tests/partition_table/data/prepare.sql index 6c37555fa3d..3dc28c3b0b1 100644 --- a/tests/integration_tests/partition_table/data/prepare.sql +++ b/tests/integration_tests/partition_table/data/prepare.sql @@ -26,4 +26,13 @@ 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)); +insert into t1 values (-1),(6),(13); +update t1 set a=a-22 where a=20; +delete from t1 where a = 5; +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)); +insert into t1 values (-3),(5),(14),(22),(30),(100); +update t1 set a=a-16 where a=12; +delete from t1 where a = 29; + create table finish_mark (a int primary key);