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

binlog-filter: add VIEW related type #405

Merged
merged 1 commit into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/binlog-filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const (
RenameTable EventType = "rename table"
CreateIndex EventType = "create index"
DropIndex EventType = "drop index"
CreateView EventType = "create view"
DropView EventType = "drop view"
AlertTable EventType = "alter table"
// if need, add more AlertTableOption = "alert table option"

Expand All @@ -72,7 +74,8 @@ func ClassifyEvent(event EventType) (EventType, error) {
switch event {
case InsertEvent, UpdateEvent, DeleteEvent:
return dml, nil
case CreateDatabase, DropDatabase, CreateTable, DropTable, TruncateTable, RenameTable, CreateIndex, DropIndex, AlertTable:
case CreateDatabase, DropDatabase, CreateTable, DropTable, TruncateTable, RenameTable,
CreateIndex, DropIndex, CreateView, DropView, AlertTable:
return ddl, nil
case NullEvent:
return NullEvent, nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/binlog-filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type testFilterSuite struct{}

func (t *testFilterSuite) TestFilter(c *C) {
rules := []*BinlogEventRule{
{"Test_1_*", "abc*", []EventType{DeleteEvent, InsertEvent, CreateIndex, DropIndex}, []string{"^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"}, nil, Ignore},
{"Test_1_*", "abc*", []EventType{DeleteEvent, InsertEvent, CreateIndex, DropIndex, DropView}, []string{"^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"}, nil, Ignore},
{"xxx_*", "abc_*", []EventType{AllDML, NoneDDL}, nil, nil, Ignore},
{"yyy_*", "abc_*", []EventType{EventType("ALL DML")}, nil, nil, Do},
}
Expand All @@ -54,6 +54,7 @@ func (t *testFilterSuite) TestFilter(c *C) {
{"xxx_1", "abc_1", CreateIndex, "", Do},
{"yyy_1", "abc_1", InsertEvent, "", Do},
{"yyy_1", "abc_1", CreateIndex, "", Ignore},
{"test_1_a", "abc1", DropView, "", Ignore},
}

// initial binlog event filter
Expand Down Expand Up @@ -87,6 +88,7 @@ func (t *testFilterSuite) TestFilter(c *C) {
cases[10].action = Ignore // match none event and create index
cases[11].action = Ignore // no match
cases[12].action = Do // match all ddl
cases[13].action = Do // match all ddl
for _, cs := range cases {
action, err := filter.Filter(cs.schema, cs.table, cs.event, cs.sql)
c.Assert(err, IsNil)
Expand Down
7 changes: 6 additions & 1 deletion pkg/binlog-filter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import "github.com/pingcap/parser/ast"

// AstToDDLEvent returns filter.DDLEvent
func AstToDDLEvent(node ast.StmtNode) EventType {
switch node.(type) {
switch n := node.(type) {
case *ast.CreateDatabaseStmt:
return CreateDatabase
case *ast.DropDatabaseStmt:
return DropDatabase
case *ast.CreateTableStmt:
return CreateTable
case *ast.DropTableStmt:
if n.IsView {
return DropView
}
return DropTable
case *ast.TruncateTableStmt:
return TruncateTable
Expand All @@ -36,6 +39,8 @@ func AstToDDLEvent(node ast.StmtNode) EventType {
return DropIndex
case *ast.AlterTableStmt:
return AlertTable
case *ast.CreateViewStmt:
return CreateView
}

return NullEvent
Expand Down