Skip to content

Commit e817d98

Browse files
sudevvaAndrii Sudiev
and
Andrii Sudiev
authored
add OnRowsQueryEvent to EventHandler (#841)
Co-authored-by: Andrii Sudiev <[email protected]>
1 parent 053c307 commit e817d98

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

canal/handler.go

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ type EventHandler interface {
1717
OnGTID(header *replication.EventHeader, gtidEvent mysql.BinlogGTIDEvent) error
1818
// OnPosSynced Use your own way to sync position. When force is true, sync position immediately.
1919
OnPosSynced(header *replication.EventHeader, pos mysql.Position, set mysql.GTIDSet, force bool) error
20+
// OnRowsQueryEvent is called when binlog_rows_query_log_events=ON for each DML query.
21+
// You'll get the original executed query, with comments if present.
22+
// It will be called before OnRow.
23+
OnRowsQueryEvent(e *replication.RowsQueryEvent) error
2024
String() string
2125
}
2226

@@ -40,6 +44,9 @@ func (h *DummyEventHandler) OnGTID(*replication.EventHeader, mysql.BinlogGTIDEve
4044
func (h *DummyEventHandler) OnPosSynced(*replication.EventHeader, mysql.Position, mysql.GTIDSet, bool) error {
4145
return nil
4246
}
47+
func (h *DummyEventHandler) OnRowsQueryEvent(*replication.RowsQueryEvent) error {
48+
return nil
49+
}
4350

4451
func (h *DummyEventHandler) String() string { return "DummyEventHandler" }
4552

canal/sync.go

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ func (c *Canal) runSyncBinlog() error {
128128
if err := c.eventHandler.OnGTID(ev.Header, e); err != nil {
129129
return errors.Trace(err)
130130
}
131+
case *replication.RowsQueryEvent:
132+
if err := c.eventHandler.OnRowsQueryEvent(e); err != nil {
133+
return errors.Trace(err)
134+
}
131135
case *replication.QueryEvent:
132136
stmts, _, err := c.parser.Parse(string(e.Query), "", "")
133137
if err != nil {

0 commit comments

Comments
 (0)