Skip to content

Commit

Permalink
add OnRowsQueryEvent to EventHandler (#841)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrii Sudiev <[email protected]>
  • Loading branch information
sudevva and Andrii Sudiev authored Dec 27, 2023
1 parent 053c307 commit e817d98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions canal/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type EventHandler interface {
OnGTID(header *replication.EventHeader, gtidEvent mysql.BinlogGTIDEvent) error
// OnPosSynced Use your own way to sync position. When force is true, sync position immediately.
OnPosSynced(header *replication.EventHeader, pos mysql.Position, set mysql.GTIDSet, force bool) error
// OnRowsQueryEvent is called when binlog_rows_query_log_events=ON for each DML query.
// You'll get the original executed query, with comments if present.
// It will be called before OnRow.
OnRowsQueryEvent(e *replication.RowsQueryEvent) error
String() string
}

Expand All @@ -40,6 +44,9 @@ func (h *DummyEventHandler) OnGTID(*replication.EventHeader, mysql.BinlogGTIDEve
func (h *DummyEventHandler) OnPosSynced(*replication.EventHeader, mysql.Position, mysql.GTIDSet, bool) error {
return nil
}
func (h *DummyEventHandler) OnRowsQueryEvent(*replication.RowsQueryEvent) error {
return nil
}

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

Expand Down
4 changes: 4 additions & 0 deletions canal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (c *Canal) runSyncBinlog() error {
if err := c.eventHandler.OnGTID(ev.Header, e); err != nil {
return errors.Trace(err)
}
case *replication.RowsQueryEvent:
if err := c.eventHandler.OnRowsQueryEvent(e); err != nil {
return errors.Trace(err)
}
case *replication.QueryEvent:
stmts, _, err := c.parser.Parse(string(e.Query), "", "")
if err != nil {
Expand Down

0 comments on commit e817d98

Please sign in to comment.