binlogsync

package
v0.0.0-...-6f8fa1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2016 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MySQLFlavor   = "mysql"
	MariaDBFlavor = "mariadb"
)

Use flavor for different MySQL versions,

View Source
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

func NewCanal(dsn *mysql.Config, db Option, opts ...Option) (*Canal, error)

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

func (c *Canal) CheckBinlogRowImage(ctx context.Context, image string) error

Check MySQL binlog row image, must be in FULL, MINIMAL, NOBLOB

func (*Canal) Close

func (c *Canal) Close() error

Close closes all underlying connections

func (*Canal) FindTable

func (c *Canal) FindTable(ctx context.Context, id int, tableName string) (csdb.Table, error)

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) Start

func (c *Canal) Start(ctx context.Context) error

func (*Canal) SyncedPosition

func (m *Canal) SyncedPosition() csdb.MasterStatus

type DBer

type DBer interface {
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	Close() error
}

type Option

type Option func(*Canal) error

Option applies multiple options to the Canal type.

func WithConfigurationWriter

func WithConfigurationWriter(w config.Writer) Option

WithConfigurationWriter used to persists the current binlog position.

func WithDB

func WithDB(db *sql.DB) Option

WithDB allows to set your own DB connection.

func WithMySQL

func WithMySQL() Option

WithMySQL adds the database/sql.DB driver including a ping to the database.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL