Skip to content

Add OnRowsQueryEvent to EventHandler #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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