event

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RowFlagsEndOfStatement     uint16 = 0x0001
	RowFlagsNoForeignKeyChecks uint16 = 0x0002
	RowFlagsNoUniqueKeyChecks  uint16 = 0x0004
	RowFlagsRowHasAColumns     uint16 = 0x0008
)

flags used in RowsEvent.

View Source
const (
	// GTIDFlagsCommitYes represents a GTID flag with [commit=yes].
	// in `Row` binlog format, this will appear in GTID event before DDL query event.
	GTIDFlagsCommitYes uint8 = 1

	// MinUserVarEventLen represents the minimum event length for a USER_VAR_EVENT with checksum
	MinUserVarEventLen = uint32(eventHeaderLen+4+1+1) + crc32Len // 29 bytes
	// MinQueryEventLen represents the minimum event length for a QueryEvent with checksum
	MinQueryEventLen = uint32(eventHeaderLen+4+4+1+2+2+1+1) + crc32Len // 38 bytes
)

Variables

This section is empty.

Functions

func GTIDIncrease

func GTIDIncrease(flavor string, gSet gtid.Set) (gtid.Set, error)

GTIDIncrease returns a new GTID with GNO/SequenceNumber +1.

func GTIDsFromMariaDBGTIDListEvent

func GTIDsFromMariaDBGTIDListEvent(e *replication.BinlogEvent) (gtid.Set, error)

GTIDsFromMariaDBGTIDListEvent get GTID set from a MariaDBGTIDListEvent.

func GTIDsFromPreviousGTIDsEvent

func GTIDsFromPreviousGTIDsEvent(e *replication.BinlogEvent) (gtid.Set, error)

GTIDsFromPreviousGTIDsEvent get GTID set from a PreviousGTIDsEvent.

func GenCommonFileHeader

func GenCommonFileHeader(flavor string, serverID uint32, gSet gtid.Set) ([]*replication.BinlogEvent, []byte, error)

GenCommonFileHeader generates a common binlog file header. for MySQL:

  1. BinLogFileHeader, [ fe `bin` ]
  2. FormatDescriptionEvent
  3. PreviousGTIDsEvent

for MariaDB:

  1. BinLogFileHeader, [ fe `bin` ]
  2. FormatDescriptionEvent
  3. MariadbGTIDListEvent -. MariadbBinlogCheckPointEvent, not added yet

func GenCommonGTIDEvent

func GenCommonGTIDEvent(flavor string, serverID uint32, latestPos uint32, gSet gtid.Set) (*replication.BinlogEvent, error)

GenCommonGTIDEvent generates a common GTID event.

func GenDummyEvent

func GenDummyEvent(header *replication.EventHeader, latestPos uint32, eventSize uint32) (*replication.BinlogEvent, error)

GenDummyEvent generates a dummy QueryEvent or a dummy USER_VAR_EVENT. Dummy events often used to fill the holes in a relay log file which lacking some events from the master. The minimum size is 29 bytes (19 bytes header + 6 bytes body for a USER_VAR_EVENT + 4 bytes checksum). ref: https://dev.mysql.com/doc/internals/en/user-var-event.html ref: https://github.com/MariaDB/server/blob/a765b19e5ca31a3d866cdbc8bef3a6f4e5e44688/sql/log_event.cc#L4950

func GenEventHeader

func GenEventHeader(header *replication.EventHeader) ([]byte, error)

GenEventHeader generates a EventHeader's raw data according to a passed-in EventHeader struct. ref: https://dev.mysql.com/doc/internals/en/binlog-event-header.html

func GenFormatDescriptionEvent

func GenFormatDescriptionEvent(header *replication.EventHeader, latestPos uint32) (*replication.BinlogEvent, error)

GenFormatDescriptionEvent generates a FormatDescriptionEvent. ref: https://dev.mysql.com/doc/internals/en/format-description-event.html.

func GenGTIDEvent

func GenGTIDEvent(header *replication.EventHeader, latestPos uint32, gtidFlags uint8, uuid string, gno int64, lastCommitted int64, sequenceNumber int64) (*replication.BinlogEvent, error)

GenGTIDEvent generates a GTIDEvent. MySQL has no internal doc for GTID_EVENT. we ref the `GTIDEvent.Decode` in go-mysql. `uuid` is the UUID part of the GTID, like `9f61c5f9-1eef-11e9-b6cf-0242ac140003`. `gno` is the GNO part of the GTID, like `6`.

func GenMariaDBGTIDEvent

func GenMariaDBGTIDEvent(header *replication.EventHeader, latestPos uint32, sequenceNum uint64, domainID uint32) (*replication.BinlogEvent, error)

GenMariaDBGTIDEvent generates a MariadbGTIDEvent. ref: https://mariadb.com/kb/en/library/gtid_event/

func GenMariaDBGTIDListEvent

func GenMariaDBGTIDListEvent(header *replication.EventHeader, latestPos uint32, gSet gtid.Set) (*replication.BinlogEvent, error)

GenMariaDBGTIDListEvent generates a MariadbGTIDListEvent. ref: https://mariadb.com/kb/en/library/gtid_list_event/

func GenPreviousGTIDsEvent

func GenPreviousGTIDsEvent(header *replication.EventHeader, latestPos uint32, gSet gtid.Set) (*replication.BinlogEvent, error)

GenPreviousGTIDsEvent generates a PreviousGTIDsEvent. MySQL has no internal doc for PREVIOUS_GTIDS_EVENT. we ref:

a. https://github.com/vitessio/vitess/blob/28e7e5503a6c3d3b18d4925d95f23ebcb6f25c8e/go/mysql/binlog_event_mysql56.go#L56
b. https://dev.mysql.com/doc/internals/en/com-binlog-dump-gtid.html

func GenQueryEvent

func GenQueryEvent(header *replication.EventHeader, latestPos uint32, slaveProxyID uint32, executionTime uint32, errorCode uint16, statusVars []byte, schema []byte, query []byte) (*replication.BinlogEvent, error)

GenQueryEvent generates a QueryEvent. ref: https://dev.mysql.com/doc/internals/en/query-event.html ref: http://blog.51cto.com/yanzongshuai/2087782 `statusVars` should be generated out of this function, we can implement it later. `len(query)` must > 0.

func GenRotateEvent

func GenRotateEvent(header *replication.EventHeader, latestPos uint32, nextLogName []byte, position uint64) (*replication.BinlogEvent, error)

GenRotateEvent generates a RotateEvent. ref: https://dev.mysql.com/doc/internals/en/rotate-event.html

func GenRowsEvent

func GenRowsEvent(header *replication.EventHeader, latestPos uint32, eventType replication.EventType, tableID uint64, rowsFlags uint16, rows [][]interface{}, columnType []byte, tableMapEv *replication.BinlogEvent) (*replication.BinlogEvent, error)

GenRowsEvent generates a RowsEvent. RowsEvent includes:

WRITE_ROWS_EVENTv0, WRITE_ROWS_EVENTv1, WRITE_ROWS_EVENTv2
UPDATE_ROWS_EVENTv0, UPDATE_ROWS_EVENTv1, UPDATE_ROWS_EVENTv2
DELETE_ROWS_EVENTv0, DELETE_ROWS_EVENTv1, DELETE_ROWS_EVENTv2

ref: https://dev.mysql.com/doc/internals/en/rows-event.html ref: http://blog.51cto.com/yanzongshuai/2090894

func GenTableMapEvent

func GenTableMapEvent(header *replication.EventHeader, latestPos uint32, tableID uint64, schema []byte, table []byte, columnType []byte) (*replication.BinlogEvent, error)

GenTableMapEvent generates a TableMapEvent. ref: https://dev.mysql.com/doc/internals/en/table-map-event.html ref: https://dev.mysql.com/doc/internals/en/describing-packets.html#type-lenenc_int ref: http://blog.51cto.com/yanzongshuai/2090758 `len(schema)` must > 0, `len(table)` must > 0, `len(columnType)` must > 0. `columnType` should be generated out of this function, we can implement it later.

func GenXIDEvent

func GenXIDEvent(header *replication.EventHeader, latestPos uint32, xid uint64) (*replication.BinlogEvent, error)

GenXIDEvent generates a XIDEvent. ref: https://dev.mysql.com/doc/internals/en/xid-event.html

Types

type DDLDMLResult

type DDLDMLResult struct {
	Events     []*replication.BinlogEvent
	Data       []byte // data contain all events
	LatestPos  uint32
	LatestGTID gtid.Set
}

DDLDMLResult represents a binlog event result for generated DDL/DML.

func GenCreateDatabaseEvents

func GenCreateDatabaseEvents(flavor string, serverID uint32, latestPos uint32, latestGTID gtid.Set, schema string) (*DDLDMLResult, error)

GenCreateDatabaseEvents generates binlog events for `CREATE DATABASE`. events: [GTIDEvent, QueryEvent]

func GenCreateTableEvents

func GenCreateTableEvents(flavor string, serverID uint32, latestPos uint32, latestGTID gtid.Set, schema string, query string) (*DDLDMLResult, error)

GenCreateTableEvents generates binlog events for `CREATE TABLE`. events: [GTIDEvent, QueryEvent] NOTE: we do not support all `column type` and `column meta` for DML now, so the caller should restrict the `query` statement.

func GenDDLEvents

func GenDDLEvents(flavor string, serverID uint32, latestPos uint32, latestGTID gtid.Set, schema string, query string) (*DDLDMLResult, error)

GenDDLEvents generates binlog events for DDL statements. events: [GTIDEvent, QueryEvent]

func GenDMLEvents

func GenDMLEvents(flavor string, serverID uint32, latestPos uint32, latestGTID gtid.Set, eventType replication.EventType, xid uint64, dmlData []*DMLData) (*DDLDMLResult, error)

GenDMLEvents generates binlog events for `INSERT`/`UPDATE`/`DELETE`. events: [GTIDEvent, QueryEvent, TableMapEvent, RowsEvent, ..., XIDEvent] NOTE: multi <TableMapEvent, RowsEvent> pairs can be in events.

func GenDropDatabaseEvents

func GenDropDatabaseEvents(flavor string, serverID uint32, latestPos uint32, latestGTID gtid.Set, schema string) (*DDLDMLResult, error)

GenDropDatabaseEvents generates binlog events for `DROP DATABASE`. events: [GTIDEvent, QueryEvent]

func GenDropTableEvents

func GenDropTableEvents(flavor string, serverID uint32, latestPos uint32, latestGTID gtid.Set, schema string, table string) (*DDLDMLResult, error)

GenDropTableEvents generates binlog events for `DROP TABLE`. events: [GTIDEvent, QueryEvent]

type DMLData

type DMLData struct {
	TableID    uint64
	Schema     string
	Table      string
	ColumnType []byte
	Rows       [][]interface{}
}

DMLData represents data used to generate events for DML statements.

type Generator

type Generator struct {
	Flavor        string
	ServerID      uint32
	LatestPos     uint32
	LatestGTID    gtid.Set
	PreviousGTIDs gtid.Set
	LatestXID     uint64
}

Generator represents a binlog events generator.

func NewGenerator

func NewGenerator(flavor string, serverID uint32, latestPos uint32, latestGTID gtid.Set, previousGTIDs gtid.Set, latestXID uint64) (*Generator, error)

NewGenerator creates a new instance of Generator.

func (*Generator) GenCreateDatabaseEvents

func (g *Generator) GenCreateDatabaseEvents(schema string) ([]*replication.BinlogEvent, []byte, error)

GenCreateDatabaseEvents generates binlog events for `CREATE DATABASE`. events: [GTIDEvent, QueryEvent]

func (*Generator) GenCreateTableEvents

func (g *Generator) GenCreateTableEvents(schema string, query string) ([]*replication.BinlogEvent, []byte, error)

GenCreateTableEvents generates binlog events for `CREATE TABLE`. events: [GTIDEvent, QueryEvent]

func (*Generator) GenDDLEvents

func (g *Generator) GenDDLEvents(schema string, query string) ([]*replication.BinlogEvent, []byte, error)

GenDDLEvents generates binlog events for DDL statements. events: [GTIDEvent, QueryEvent]

func (*Generator) GenDMLEvents

func (g *Generator) GenDMLEvents(eventType replication.EventType, dmlData []*DMLData) ([]*replication.BinlogEvent, []byte, error)

GenDMLEvents generates binlog events for `INSERT`/`UPDATE`/`DELETE`. events: [GTIDEvent, QueryEvent, TableMapEvent, RowsEvent, ..., XIDEvent] NOTE: multi <TableMapEvent, RowsEvent> pairs can be in events.

func (*Generator) GenDropDatabaseEvents

func (g *Generator) GenDropDatabaseEvents(schema string) ([]*replication.BinlogEvent, []byte, error)

GenDropDatabaseEvents generates binlog events for `DROP DATABASE`. events: [GTIDEvent, QueryEvent]

func (*Generator) GenDropTableEvents

func (g *Generator) GenDropTableEvents(schema string, table string) ([]*replication.BinlogEvent, []byte, error)

GenDropTableEvents generates binlog events for `DROP TABLE`. events: [GTIDEvent, QueryEvent]

func (*Generator) GenFileHeader

func (g *Generator) GenFileHeader() ([]*replication.BinlogEvent, []byte, error)

GenFileHeader generates a binlog file header, including to PreviousGTIDsEvent/MariadbGTIDListEvent. for MySQL:

  1. BinLogFileHeader, [ fe `bin` ]
  2. FormatDescriptionEvent
  3. PreviousGTIDsEvent

for MariaDB:

  1. BinLogFileHeader, [ fe `bin` ]
  2. FormatDescriptionEvent
  3. MariadbGTIDListEvent

type SID

SID represents a SERVER_UUID in GTIDEvent/PrevGTIDEvent.

func ParseSID

func ParseSID(s string) (SID, error)

ParseSID parses a SID from its string representation. ref https://github.com/vitessio/vitess/blob/869543aa2c4c467f146ba7d77f6d090ca7f8a862/go/mysql/mysql56_gtid.go#L66.

func (SID) Bytes

func (sid SID) Bytes() []byte

Bytes returns the byte slices representation of SID.

func (SID) String

func (sid SID) String() string

Jump to

Keyboard shortcuts

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