Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#2308
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
Rustin170506 authored and ti-chi-bot committed Jul 17, 2021
1 parent f699ec4 commit 779849f
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions pkg/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ import (
filterV2 "github.com/pingcap/tidb-tools/pkg/table-filter"
)

// Filter is a event filter implementation
// Filter is a event filter implementation.
type Filter struct {
filter filterV2.Filter
ignoreTxnStartTs []uint64
ddlAllowlist []model.ActionType
isCyclicEnabled bool
}

<<<<<<< HEAD
// NewFilter creates a filter
func NewFilter(cfg *config.ReplicaConfig) (*Filter, error) {
=======
// VerifyRules checks the filter rules in the configuration
// and returns an invalid rule error if the verification fails, otherwise it will return the parsed filter.
func VerifyRules(cfg *config.ReplicaConfig) (filterV2.Filter, error) {
>>>>>>> bb234085 (filter: refine comments and function visibility (#2308))
var f filterV2.Filter
var err error
if len(cfg.Filter.Rules) == 0 && cfg.Filter.MySQLReplicationRules != nil {
Expand All @@ -46,6 +52,20 @@ func NewFilter(cfg *config.ReplicaConfig) (*Filter, error) {
if err != nil {
return nil, cerror.WrapError(cerror.ErrFilterRuleInvalid, err)
}
<<<<<<< HEAD
=======

return f, nil
}

// NewFilter creates a filter.
func NewFilter(cfg *config.ReplicaConfig) (*Filter, error) {
f, err := VerifyRules(cfg)
if err != nil {
return nil, cerror.WrapError(cerror.ErrFilterRuleInvalid, err)
}

>>>>>>> bb234085 (filter: refine comments and function visibility (#2308))
if !cfg.CaseSensitive {
f = filterV2.CaseInsensitive(f)
}
Expand All @@ -67,9 +87,9 @@ func (f *Filter) shouldIgnoreStartTs(ts uint64) bool {
}

// ShouldIgnoreTable returns true if the specified table should be ignored by this change feed.
// Set `tbl` to an empty string to test against the whole database.
// NOTICE: Set `tbl` to an empty string to test against the whole database.
func (f *Filter) ShouldIgnoreTable(db, tbl string) bool {
if IsSysSchema(db) {
if isSysSchema(db) {
return true
}
if f.isCyclicEnabled && mark.IsMarkTable(db, tbl) {
Expand Down Expand Up @@ -99,7 +119,7 @@ func (f *Filter) ShouldIgnoreDDLEvent(ts uint64, ddlType model.ActionType, schem
return f.shouldIgnoreStartTs(ts) || shouldIgnoreTableOrSchema
}

// ShouldDiscardDDL returns true if this DDL should be discarded
// ShouldDiscardDDL returns true if this DDL should be discarded.
func (f *Filter) ShouldDiscardDDL(ddlType model.ActionType) bool {
if !f.shouldDiscardByBuiltInDDLAllowlist(ddlType) {
return false
Expand Down Expand Up @@ -169,7 +189,7 @@ func (f *Filter) shouldDiscardByBuiltInDDLAllowlist(ddlType model.ActionType) bo
return true
}

// IsSysSchema returns true if the given schema is a system schema
func IsSysSchema(db string) bool {
// isSysSchema returns true if the given schema is a system schema
func isSysSchema(db string) bool {
return filterV1.IsSystemSchema(db)
}

0 comments on commit 779849f

Please sign in to comment.