Skip to content

Commit e1dd2db

Browse files
committed
add support for rowsEventDecodeFunc in Canal
1 parent 5acb569 commit e1dd2db

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

canal/canal.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,12 @@ func (c *Canal) prepareSyncer() error {
463463
Dialer: c.cfg.Dialer,
464464
Localhost: c.cfg.Localhost,
465465
EventCacheCount: c.cfg.EventCacheCount,
466-
RowsEventDecodeFunc: func(event *replication.RowsEvent, data []byte) error {
466+
}
467+
468+
if c.cfg.RowsEventDecodeFunc != nil {
469+
cfg.RowsEventDecodeFunc = c.cfg.RowsEventDecodeFunc
470+
} else {
471+
cfg.RowsEventDecodeFunc = func(event *replication.RowsEvent, data []byte) error {
467472
pos, err := event.DecodeHeader(data)
468473
if err != nil {
469474
return err
@@ -475,7 +480,7 @@ func (c *Canal) prepareSyncer() error {
475480
}
476481

477482
return event.DecodeData(pos, data)
478-
},
483+
}
479484
}
480485

481486
if strings.Contains(c.cfg.Addr, "/") {

canal/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/go-mysql-org/go-mysql/client"
1616
"github.com/go-mysql-org/go-mysql/mysql"
17+
"github.com/go-mysql-org/go-mysql/replication"
1718
)
1819

1920
type DumpConfig struct {
@@ -71,6 +72,9 @@ type Config struct {
7172
IncludeTableRegex []string `toml:"include_table_regex"`
7273
ExcludeTableRegex []string `toml:"exclude_table_regex"`
7374

75+
// Allows to specify a custom function to decode RowsEvent. This can be used to skip decoding of some events.
76+
RowsEventDecodeFunc func(*replication.RowsEvent, []byte) error
77+
7478
// discard row event without table meta
7579
DiscardNoMetaRowEvent bool `toml:"discard_no_meta_row_event"`
7680

0 commit comments

Comments
 (0)