From 627e9c95dcef1b043e0b177e798ae4a9f267e149 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 7bdc8a57f..1fd05d242 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 @@ -170,7 +172,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 97603c6b6..93d04e865 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)