Documentation ¶
Index ¶
- Constants
- type Canal
- func (c *Canal) CheckBinlogRowImage(ctx context.Context, image string) error
- func (c *Canal) Close() error
- func (c *Canal) FindTable(ctx context.Context, id int, tableName string) (csdb.Table, error)
- func (c *Canal) RegisterRowsEventHandler(h RowsEventHandler)
- func (c *Canal) Start(ctx context.Context) error
- func (m *Canal) SyncedPosition() csdb.MasterStatus
- type DBer
- type Option
- type RowsEventHandler
Constants ¶
const ( MySQLFlavor = "mysql" MariaDBFlavor = "mariadb" )
Use flavor for different MySQL versions,
const ( UpdateAction = "update" InsertAction = "insert" DeleteAction = "delete" )
Action constants to figure out the type of an event. Those constants will be passed to the interface RowsEventHandler.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canal ¶
type Canal struct { // BackendPosition initial idea. writing supported but not loading BackendPosition cfgmodel.Str // DSN contains the parsed DSN DSN *mysql.Config Log log.Logger // contains filtered or unexported fields }
Canal can sync your MySQL data. MySQL must use the binlog format ROW.
func NewCanal ¶
NewCanal creates a new canal object to start reading the MySQL binary log. If you don't provide a database connection option this function will panic. export CS_DSN='root:PASSWORD@tcp(localhost:3306)/DATABASE_NAME?BinlogSlaveId=100&BinlogStartFile=mysql-bin.000002&BinlogStartPosition=4'
func (*Canal) CheckBinlogRowImage ¶
Check MySQL binlog row image, must be in FULL, MINIMAL, NOBLOB
func (*Canal) FindTable ¶
FindTable tries to find a table by its ID. If the table cannot be found by the first search, it will add the table to the internal map and performs a column load from the information_schema and then returns the fully defined table.
func (*Canal) RegisterRowsEventHandler ¶
func (c *Canal) RegisterRowsEventHandler(h RowsEventHandler)
RegisterRowsEventHandler adds a new event handler to the internal list.
func (*Canal) SyncedPosition ¶
func (m *Canal) SyncedPosition() csdb.MasterStatus
type Option ¶
Option applies multiple options to the Canal type.
func WithConfigurationWriter ¶
WithConfigurationWriter used to persists the current binlog position.
type RowsEventHandler ¶
type RowsEventHandler interface { // Do function handles a RowsEvent bound to a specific database. If it // returns an error behaviour of "Interrupted", the canal type will stop the // syncer. Binlog has three update event version, v0, v1 and v2. For v1 and // v2, the rows number must be even. Two rows for one event, format is // [before update row, after update row] for update v0, only one row for a // event, and we don't support this version yet. The Do function will run in // its own Goroutine. Do(ctx context.Context, action string, t csdb.Table, rows [][]interface{}) error // Complete runs before a binlog rotation event happens. Same error rules // apply here like for function Do(). The Complete function will run in its // own Goroutine. Complete(context.Context) error // String returns the name of the handler String() string }
RowsEventHandler calls your code when an event gets dispatched.