2017-02-12 11:13:54 +00:00
|
|
|
package canal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/siddontang/go-mysql/mysql"
|
2019-01-01 08:57:46 +00:00
|
|
|
"github.com/siddontang/go-mysql/replication"
|
2017-02-12 11:13:54 +00:00
|
|
|
)
|
|
|
|
|
2019-01-01 08:57:46 +00:00
|
|
|
type EventHandler interface {
|
|
|
|
OnRotate(roateEvent *replication.RotateEvent) error
|
|
|
|
// OnTableChanged is called when the table is created, altered, renamed or dropped.
|
|
|
|
// You need to clear the associated data like cache with the table.
|
|
|
|
// It will be called before OnDDL.
|
|
|
|
OnTableChanged(schema string, table string) error
|
|
|
|
OnDDL(nextPos mysql.Position, queryEvent *replication.QueryEvent) error
|
|
|
|
OnRow(e *RowsEvent) error
|
|
|
|
OnXID(nextPos mysql.Position) error
|
|
|
|
OnGTID(gtid mysql.GTIDSet) error
|
|
|
|
// OnPosSynced Use your own way to sync position. When force is true, sync position immediately.
|
|
|
|
OnPosSynced(pos mysql.Position, force bool) error
|
2017-02-12 11:13:54 +00:00
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2019-01-01 08:57:46 +00:00
|
|
|
type DummyEventHandler struct {
|
2017-02-12 11:13:54 +00:00
|
|
|
}
|
|
|
|
|
2019-01-01 08:57:46 +00:00
|
|
|
func (h *DummyEventHandler) OnRotate(*replication.RotateEvent) error { return nil }
|
|
|
|
func (h *DummyEventHandler) OnTableChanged(schema string, table string) error { return nil }
|
|
|
|
func (h *DummyEventHandler) OnDDL(nextPos mysql.Position, queryEvent *replication.QueryEvent) error {
|
2017-02-12 11:13:54 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-01-01 08:57:46 +00:00
|
|
|
func (h *DummyEventHandler) OnRow(*RowsEvent) error { return nil }
|
|
|
|
func (h *DummyEventHandler) OnXID(mysql.Position) error { return nil }
|
|
|
|
func (h *DummyEventHandler) OnGTID(mysql.GTIDSet) error { return nil }
|
|
|
|
func (h *DummyEventHandler) OnPosSynced(mysql.Position, bool) error { return nil }
|
|
|
|
func (h *DummyEventHandler) String() string { return "DummyEventHandler" }
|
|
|
|
|
|
|
|
// `SetEventHandler` registers the sync handler, you must register your
|
|
|
|
// own handler before starting Canal.
|
|
|
|
func (c *Canal) SetEventHandler(h EventHandler) {
|
|
|
|
c.eventHandler = h
|
|
|
|
}
|