From c4bdf178b3d6ae0242332aa7ef8448b74eb5b45c Mon Sep 17 00:00:00 2001 From: GMHDBJD <35025882+GMHDBJD@users.noreply.github.com> Date: Thu, 28 Dec 2023 11:55:19 +0800 Subject: [PATCH] binlog-filter: log error instead of return (#761) --- pkg/binlog-filter/filter.go | 4 +++- pkg/binlog-filter/filter_test.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/binlog-filter/filter.go b/pkg/binlog-filter/filter.go index 8f66d25f..a4e38aa8 100644 --- a/pkg/binlog-filter/filter.go +++ b/pkg/binlog-filter/filter.go @@ -18,7 +18,9 @@ import ( "strings" "github.com/pingcap/errors" + "github.com/pingcap/log" selector "github.com/pingcap/tidb-tools/pkg/table-rule-selector" + "go.uber.org/zap" ) // ActionType indicates how to handle matched items @@ -216,7 +218,7 @@ func NewBinlogEvent(caseSensitive bool, rules []*BinlogEventRule) (*BinlogEvent, for _, rule := range rules { if err := b.AddRule(rule); err != nil { - return nil, errors.Annotatef(err, "initial rule %+v in binlog event filter", rule) + log.Error("invalid binlog event rule", zap.Error(err)) } } diff --git a/pkg/binlog-filter/filter_test.go b/pkg/binlog-filter/filter_test.go index 55e564c4..fe73823b 100644 --- a/pkg/binlog-filter/filter_test.go +++ b/pkg/binlog-filter/filter_test.go @@ -34,6 +34,7 @@ func (t *testFilterSuite) TestFilter(c *C) { {"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}, + {"Test_1_*", "abc*", []EventType{"wrong event"}, []string{"^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"}, nil, Ignore}, } cases := []struct { @@ -77,6 +78,7 @@ func (t *testFilterSuite) TestFilter(c *C) { rules[0].Events = []EventType{} rules[1].Action = Do rules[2].Events = []EventType{"ALL DDL"} + rules = rules[:3] for _, rule := range rules { err = filter.UpdateRule(rule) c.Assert(err, IsNil)