From a020d2cdfc5a9654c6a03066bb9089960a5c3d87 Mon Sep 17 00:00:00 2001 From: GMHDBJD <35025882+GMHDBJD@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:44:20 +0800 Subject: [PATCH] add drop column, rename column/index for incompatible ddl changes (#751) --- pkg/binlog-filter/filter.go | 51 ++++++++++++++++---------------- pkg/binlog-filter/filter_test.go | 16 +++++----- pkg/binlog-filter/util.go | 10 +++---- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/pkg/binlog-filter/filter.go b/pkg/binlog-filter/filter.go index d16e98dca..8f66d25fd 100644 --- a/pkg/binlog-filter/filter.go +++ b/pkg/binlog-filter/filter.go @@ -81,11 +81,11 @@ const ( ValueRangeDecrease EventType = "value range decrease" PrecisionDecrease EventType = "precision decrease" ModifyColumn EventType = "modify column" - Rename EventType = "rename" - Drop EventType = "drop" - Truncate EventType = "truncate" - ModifyPK EventType = "modify pk" - ModifyUK EventType = "modify uk" + RenameColumn EventType = "rename column" + RenameIndex EventType = "rename index" + DropColumn EventType = "drop column" + DropPrimaryKey EventType = "drop primary key" + DropUniqueKey EventType = "drop unique key" ModifyDefaultValue EventType = "modify default value" ModifyConstraint EventType = "modify constaints" ModifyColumnsOrder EventType = "modify columns order" @@ -93,11 +93,11 @@ const ( ModifyCollation EventType = "modify collation" RemoveAutoIncrement EventType = "remove auto increment" ModifyStorageEngine EventType = "modify storage engine" - ReorganizePartion EventType = "reorganize partition" - RebuildPartition EventType = "rebuild partition" - CoalescePartition EventType = "coalesce partition" - SplitPartition EventType = "split partition" - ExchangePartition EventType = "exchange partition" + ReorganizePartion EventType = "reorganize table partition" + RebuildPartition EventType = "rebuild table partition" + CoalescePartition EventType = "coalesce table partition" + SplitPartition EventType = "split table partition" + ExchangePartition EventType = "exchange table partition" // NullEvent is used to represents unsupported ddl event type when we // convert a ast.StmtNode or a string to EventType. @@ -112,34 +112,26 @@ func ClassifyEvent(event EventType) (EventType, error) { DeleteEvent: return dml, nil case CreateDatabase, - DropDatabase, AlterDatabase, AlterSchema, CreateTable, - DropTable, - TruncateTable, - RenameTable, CreateIndex, - DropIndex, CreateView, DropView, AlterTable, CreateSchema, - DropSchema, - AddTablePartition, - DropTablePartition, - TruncateTablePartition: + AddTablePartition: return ddl, nil case NullEvent: return NullEvent, nil case ValueRangeDecrease, PrecisionDecrease, ModifyColumn, - Rename, - Drop, - Truncate, - ModifyPK, - ModifyUK, + RenameColumn, + RenameIndex, + DropColumn, + DropPrimaryKey, + DropUniqueKey, ModifyDefaultValue, ModifyConstraint, ModifyColumnsOrder, @@ -151,7 +143,16 @@ func ClassifyEvent(event EventType) (EventType, error) { RebuildPartition, CoalescePartition, SplitPartition, - ExchangePartition: + ExchangePartition, + + DropDatabase, + DropTable, + DropIndex, + RenameTable, + TruncateTable, + DropSchema, + DropTablePartition, + TruncateTablePartition: return incompatibleDDL, nil default: return NullEvent, errors.NotValidf("event type %s", event) diff --git a/pkg/binlog-filter/filter_test.go b/pkg/binlog-filter/filter_test.go index 97603c6b6..55e564c47 100644 --- a/pkg/binlog-filter/filter_test.go +++ b/pkg/binlog-filter/filter_test.go @@ -302,21 +302,21 @@ func (t *testFilterSuite) TestClassifyEvent(c *C) { // ddl {CreateDatabase, ddl, nil}, {CreateSchema, ddl, nil}, - {DropDatabase, ddl, nil}, - {DropSchema, ddl, nil}, + {DropDatabase, incompatibleDDL, nil}, + {DropSchema, incompatibleDDL, nil}, {AlterSchema, ddl, nil}, {CreateTable, ddl, nil}, - {DropTable, ddl, nil}, - {TruncateTable, ddl, nil}, - {RenameTable, ddl, nil}, + {DropTable, incompatibleDDL, nil}, + {TruncateTable, incompatibleDDL, nil}, + {RenameTable, incompatibleDDL, nil}, {CreateIndex, ddl, nil}, - {DropIndex, ddl, nil}, + {DropIndex, incompatibleDDL, nil}, {CreateView, ddl, nil}, {DropView, ddl, nil}, {AlterTable, ddl, nil}, {AddTablePartition, ddl, nil}, - {DropTablePartition, ddl, nil}, - {TruncateTablePartition, ddl, nil}, + {DropTablePartition, incompatibleDDL, nil}, + {TruncateTablePartition, incompatibleDDL, nil}, {"create", NullEvent, errors.NotValidf("event type %s", "create")}, {EventType("xxx"), NullEvent, errors.NotValidf("event type %s", "xxx")}, {EventType("I don't know"), NullEvent, errors.NotValidf("event type %s", "I don't know")}, diff --git a/pkg/binlog-filter/util.go b/pkg/binlog-filter/util.go index 314e624af..1a72e93da 100644 --- a/pkg/binlog-filter/util.go +++ b/pkg/binlog-filter/util.go @@ -87,11 +87,11 @@ func toEventType(es string) (EventType, error) { ValueRangeDecrease, PrecisionDecrease, ModifyColumn, - Rename, - Drop, - Truncate, - ModifyPK, - ModifyUK, + RenameColumn, + RenameIndex, + DropColumn, + DropPrimaryKey, + DropUniqueKey, ModifyDefaultValue, ModifyConstraint, ModifyColumnsOrder,