Documentation ¶
Index ¶
- Constants
- func GTIDIncrease(flavor string, gSet gmysql.GTIDSet) (gmysql.GTIDSet, error)
- func GTIDsFromMariaDBGTIDListEvent(e *replication.BinlogEvent) (gmysql.GTIDSet, error)
- func GTIDsFromPreviousGTIDsEvent(e *replication.BinlogEvent) (gmysql.GTIDSet, error)
- func GenAnonymousGTIDEvent(header *replication.EventHeader, latestPos uint32, gtidFlags uint8, ...) (*replication.BinlogEvent, error)
- func GenCommonFileHeader(flavor string, serverID uint32, gSet gmysql.GTIDSet, genGTID bool, ts int64) ([]*replication.BinlogEvent, []byte, error)
- func GenCommonGTIDEvent(flavor string, serverID uint32, latestPos uint32, gSet gmysql.GTIDSet, ...) (*replication.BinlogEvent, error)
- func GenDummyEvent(header *replication.EventHeader, latestPos uint32, eventSize uint32) (*replication.BinlogEvent, error)
- func GenEventHeader(header *replication.EventHeader) ([]byte, error)
- func GenFormatDescriptionEvent(header *replication.EventHeader, latestPos uint32) (*replication.BinlogEvent, error)
- func GenGTIDEvent(header *replication.EventHeader, latestPos uint32, gtidFlags uint8, ...) (*replication.BinlogEvent, error)
- func GenHeartbeatEvent(header *replication.EventHeader) *replication.BinlogEvent
- func GenMariaDBGTIDEvent(header *replication.EventHeader, latestPos uint32, sequenceNum uint64, ...) (*replication.BinlogEvent, error)
- func GenMariaDBGTIDListEvent(header *replication.EventHeader, latestPos uint32, gSet gmysql.GTIDSet) (*replication.BinlogEvent, error)
- func GenPreviousGTIDsEvent(header *replication.EventHeader, latestPos uint32, gSet gmysql.GTIDSet) (*replication.BinlogEvent, error)
- func GenQueryEvent(header *replication.EventHeader, latestPos uint32, slaveProxyID uint32, ...) (*replication.BinlogEvent, error)
- func GenRotateEvent(header *replication.EventHeader, latestPos uint32, nextLogName []byte, ...) (*replication.BinlogEvent, error)
- func GenRowsEvent(header *replication.EventHeader, latestPos uint32, ...) (*replication.BinlogEvent, error)
- func GenTableMapEvent(header *replication.EventHeader, latestPos uint32, tableID uint64, ...) (*replication.BinlogEvent, error)
- func GenXIDEvent(header *replication.EventHeader, latestPos uint32, xid uint64) (*replication.BinlogEvent, error)
- func GetCharsetCodecByStatusVars(statusVars []byte) (encoding.Encoding, error)
- func GetGTIDStr(e *replication.BinlogEvent) (string, error)
- func GetParserForStatusVars(statusVars []byte) (*parser.Parser, error)
- func GetServerCollationByStatusVars(statusVars []byte, idAndCollationMap map[int]string) (string, error)
- func GetTimezoneByStatusVars(statusVars []byte, upstreamTZStr string) (string, error)
- type DDLDMLResult
- type DMLData
- type Generator
- func (g *Generator) GenCreateDatabaseEvents(schema string) ([]*replication.BinlogEvent, []byte, error)
- func (g *Generator) GenCreateTableEvents(schema string, query string) ([]*replication.BinlogEvent, []byte, error)
- func (g *Generator) GenDDLEvents(schema string, query string, ts int64) ([]*replication.BinlogEvent, []byte, error)
- func (g *Generator) GenDMLEvents(eventType replication.EventType, dmlData []*DMLData, ts int64) ([]*replication.BinlogEvent, []byte, error)
- func (g *Generator) GenDropDatabaseEvents(schema string) ([]*replication.BinlogEvent, []byte, error)
- func (g *Generator) GenDropTableEvents(schema string, table string) ([]*replication.BinlogEvent, []byte, error)
- func (g *Generator) GenFileHeader(ts int64) ([]*replication.BinlogEvent, []byte, error)
- func (g *Generator) Rotate(nextName string, ts int64) (*replication.BinlogEvent, []byte, error)
- type SID
Constants ¶
const ( RowFlagsEndOfStatement uint16 = 0x0001 RowFlagsNoForeignKeyChecks uint16 = 0x0002 RowFlagsNoUniqueKeyChecks uint16 = 0x0004 RowFlagsRowHasAColumns uint16 = 0x0008 )
flags used in RowsEvent.
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 )
const ( QFlags2Code = iota QSqlModeCode QCatalog QAutoIncrement QCharsetCode QTimeZoneCode QCatalogNzCode QLcTimeNamesCode QCharsetDatabaseCode QTableMapForUpdateCode QMasterDataWrittenCode QInvokers QUpdatedDBNames QMicroseconds QCommitTS QCommitTS2 QExplicitDefaultsForTimestamp QDdlLoggedWithXid QDefaultCollationForUtf8mb4 QSqlRequirePrimaryKey QDefaultTableEncryption QHrnow = 128 )
https://dev.mysql.com/doc/internals/en/query-event.html and after Q_COMMIT_TS could be found in https://github.com/mysql/mysql-server/blob/124c7ab1d6f914637521fd4463a993aa73403513/libbinlogevents/include/statement_events.h#L500 Q_HRNOW (MariaDB) could be found in https://github.com/MariaDB/server/blob/09a1f0075a8d5752dd7b2940a20d86a040af1741/sql/log_event.h#L321
Variables ¶
This section is empty.
Functions ¶
func GTIDIncrease ¶
GTIDIncrease returns a new GTID with GNO/SequenceNumber +1.
func GTIDsFromMariaDBGTIDListEvent ¶
func GTIDsFromMariaDBGTIDListEvent(e *replication.BinlogEvent) (gmysql.GTIDSet, error)
GTIDsFromMariaDBGTIDListEvent get GTID set from a MariaDBGTIDListEvent.
func GTIDsFromPreviousGTIDsEvent ¶
func GTIDsFromPreviousGTIDsEvent(e *replication.BinlogEvent) (gmysql.GTIDSet, error)
GTIDsFromPreviousGTIDsEvent get GTID set from a PreviousGTIDsEvent.
func GenAnonymousGTIDEvent ¶
func GenAnonymousGTIDEvent(header *replication.EventHeader, latestPos uint32, gtidFlags uint8, lastCommitted int64, sequenceNumber int64) (*replication.BinlogEvent, error)
func GenCommonFileHeader ¶
func GenCommonFileHeader(flavor string, serverID uint32, gSet gmysql.GTIDSet, genGTID bool, ts int64) ([]*replication.BinlogEvent, []byte, error)
GenCommonFileHeader generates a common binlog file header. for MySQL:
- BinLogFileHeader, [ fe `bin` ]
- FormatDescriptionEvent
- PreviousGTIDsEvent, depends on genGTID
for MariaDB:
- BinLogFileHeader, [ fe `bin` ]
- FormatDescriptionEvent
- MariadbGTIDListEvent, depends on genGTID
func GenCommonGTIDEvent ¶
func GenCommonGTIDEvent(flavor string, serverID uint32, latestPos uint32, gSet gmysql.GTIDSet, anonymous bool, ts int64) (*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 GenHeartbeatEvent ¶
func GenHeartbeatEvent(header *replication.EventHeader) *replication.BinlogEvent
GenHeartbeatEvent generates a heartbeat event. ref: https://dev.mysql.com/doc/internals/en/heartbeat-event.html
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 gmysql.GTIDSet) (*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 gmysql.GTIDSet) (*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
func GetCharsetCodecByStatusVars ¶
GetCharsetCodecByStatusVars returns an encoding.Encoding to encode and decode original query if needed.
func GetGTIDStr ¶
func GetGTIDStr(e *replication.BinlogEvent) (string, error)
GetGTIDStr gets GTID string representation from a GTID event or MariaDB GTID evnets. learn from: https://github.com/go-mysql-org/go-mysql/blob/c6ab05a85eb86dc51a27ceed6d2f366a32874a24/replication/binlogsyncer.go#L732-L749
func GetParserForStatusVars ¶
GetParserForStatusVars gets a parser for binlog which is suitable for its sql_mode in statusVars.
func GetServerCollationByStatusVars ¶
func GetServerCollationByStatusVars(statusVars []byte, idAndCollationMap map[int]string) (string, error)
GetServerCollationByStatusVars gets server collation by binlog statusVars.
func GetTimezoneByStatusVars ¶
GetTimezoneByStatusVars returns the timezone of upstream for "datetime" type alter table commands. For "ALTER TABLE ADD COLUMN x DATETIME", not for "ALTER TABLE ADD COLUMN x TIMESTAMP".
Types ¶
type DDLDMLResult ¶
type DDLDMLResult struct { Events []*replication.BinlogEvent Data []byte // data contain all events LatestPos uint32 LatestGTID gmysql.GTIDSet }
DDLDMLResult represents a binlog event result for generated DDL/DML.
func GenDDLEvents ¶
func GenDDLEvents(flavor string, serverID, latestPos uint32, latestGTID mysql.GTIDSet, schema, query string, genGTID, anonymousGTID bool, ts int64) (*DDLDMLResult, error)
GenDDLEvents generates binlog events for DDL statements. events: [GTIDEvent, QueryEvent]
func GenDMLEvents ¶
func GenDMLEvents(flavor string, serverID uint32, latestPos uint32, latestGTID mysql.GTIDSet, eventType replication.EventType, xid uint64, dmlData []*DMLData, genGTID, anonymousGTID bool, ts int64) (*DDLDMLResult, error)
GenDMLEvents generates binlog events for `INSERT`/`UPDATE`/`DELETE`. if DMLData.Query is empty:
events: [GTIDEvent, QueryEvent, TableMapEvent, RowsEvent, ..., XIDEvent] NOTE: multi <TableMapEvent, RowsEvent> pairs can be in events.
if DMLData.Query is not empty:
events: [GTIDEvent, QueryEvent, QueryEvent, ..., XIDEvent] NOTE: multi <QueryEvent> can be in events.
type DMLData ¶
type DMLData struct { TableID uint64 Schema string Table string ColumnType []byte Rows [][]interface{} // if Query is not empty, we generate a Query event Query string }
DMLData represents data used to generate events for DML statements.
type Generator ¶
type Generator struct { Flavor string ServerID uint32 LatestPos uint32 LatestGTID gmysql.GTIDSet ExecutedGTIDs gmysql.GTIDSet LatestXID uint64 GenGTID bool AnonymousGTID bool }
Generator represents a binlog events generator.
func NewGenerator ¶
func NewGenerator(flavor string, serverID uint32, latestPos uint32, latestGTID gmysql.GTIDSet, previousGTIDs gmysql.GTIDSet, latestXID uint64) (*Generator, error)
NewGenerator creates a new instance of Generator.
func NewGeneratorV2 ¶
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, ts int64) ([]*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, ts int64) ([]*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(ts int64) ([]*replication.BinlogEvent, []byte, error)
GenFileHeader generates a binlog file header, including to PreviousGTIDsEvent/MariadbGTIDListEvent. for MySQL:
- BinLogFileHeader, [ fe `bin` ]
- FormatDescriptionEvent
- PreviousGTIDsEvent
for MariaDB:
- BinLogFileHeader, [ fe `bin` ]
- FormatDescriptionEvent
- MariadbGTIDListEvent
func (*Generator) Rotate ¶
func (g *Generator) Rotate(nextName string, ts int64) (*replication.BinlogEvent, []byte, error)
type SID ¶
type SID [replication.SidLength]byte
SID represents a SERVER_UUID in GTIDEvent/PrevGTIDEvent.
func ParseSID ¶
ParseSID parses a SID from its string representation. ref https://github.com/vitessio/vitess/blob/869543aa2c4c467f146ba7d77f6d090ca7f8a862/go/mysql/mysql56_gtid.go#L66.