replication

package
v2.1.0-rc.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2017 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package replication contains data structure definitions for MySQL replication related features.

Index

Constants

View Source
const (
	// TypeDecimal is MYSQL_TYPE_DECIMAL. It is deprecated.
	TypeDecimal = 0

	// TypeTiny is MYSQL_TYPE_TINY
	TypeTiny = 1

	// TypeShort is MYSQL_TYPE_SHORT
	TypeShort = 2

	// TypeLong is MYSQL_TYPE_LONG
	TypeLong = 3

	// TypeFloat is MYSQL_TYPE_FLOAT
	TypeFloat = 4

	// TypeDouble is MYSQL_TYPE_DOUBLE
	TypeDouble = 5

	// TypeNull is MYSQL_TYPE_NULL
	TypeNull = 6

	// TypeTimestamp is MYSQL_TYPE_TIMESTAMP
	TypeTimestamp = 7

	// TypeLongLong is MYSQL_TYPE_LONGLONG
	TypeLongLong = 8

	// TypeInt24 is MYSQL_TYPE_INT24
	TypeInt24 = 9

	// TypeDate is MYSQL_TYPE_DATE
	TypeDate = 10

	// TypeTime is MYSQL_TYPE_TIME
	TypeTime = 11

	// TypeDateTime is MYSQL_TYPE_DATETIME
	TypeDateTime = 12

	// TypeYear is MYSQL_TYPE_YEAR
	TypeYear = 13

	// TypeNewDate is MYSQL_TYPE_NEWDATE
	TypeNewDate = 14

	// TypeVarchar is MYSQL_TYPE_VARCHAR
	TypeVarchar = 15

	// TypeBit is MYSQL_TYPE_BIT
	TypeBit = 16

	// TypeTimestamp2 is MYSQL_TYPE_TIMESTAMP2
	TypeTimestamp2 = 17

	// TypeDateTime2 is MYSQL_TYPE_DATETIME2
	TypeDateTime2 = 18

	// TypeTime2 is MYSQL_TYPE_TIME2
	TypeTime2 = 19

	// TypeJSON is MYSQL_TYPE_JSON
	TypeJSON = 245

	// TypeNewDecimal is MYSQL_TYPE_NEWDECIMAL
	TypeNewDecimal = 246

	// TypeEnum is MYSQL_TYPE_ENUM
	TypeEnum = 247

	// TypeSet is MYSQL_TYPE_SET
	TypeSet = 248

	// TypeTinyBlob is MYSQL_TYPE_TINY_BLOB
	TypeTinyBlob = 249

	// TypeMediumBlob is MYSQL_TYPE_MEDIUM_BLOB
	TypeMediumBlob = 250

	// TypeLongBlob is MYSQL_TYPE_LONG_BLOB
	TypeLongBlob = 251

	// TypeBlob is MYSQL_TYPE_BLOB
	TypeBlob = 252

	// TypeVarString is MYSQL_TYPE_VAR_STRING
	TypeVarString = 253

	// TypeString is MYSQL_TYPE_STRING
	TypeString = 254

	// TypeGeometry is MYSQL_TYPE_GEOMETRY
	TypeGeometry = 255
)

This is the data type for a field. Values taken from include/mysql/mysql_com.h FIXME(alainjobart) this is the same info as constants describes in the go/mysql package. We will remove that package, and merge this package with go/mysqlconn as asoon as we can.

View Source
const (
	// IntVarInvalidInt is INVALID_INT_EVENT
	IntVarInvalidInt = 0

	// IntVarLastInsertID is LAST_INSERT_ID_EVENT
	IntVarLastInsertID = 1

	// IntVarInsertID is INSERT_ID_EVENT
	IntVarInsertID = 2
)

Constants for the type of an INTVAR_EVENT.

View Source
const (
	// BinlogChecksumAlgOff indicates that checksums are supported but off.
	BinlogChecksumAlgOff = 0

	// BinlogChecksumAlgCRC32 indicates that CRC32 checksums are used.
	BinlogChecksumAlgCRC32 = 1

	// BinlogChecksumAlgUndef indicates that checksums are not supported.
	BinlogChecksumAlgUndef = 255
)

Constants about the type of checksum in a packet. These constants are common between MariaDB 10.0 and MySQL 5.6.

View Source
const (
	// QFlags2Code is Q_FLAGS2_CODE
	QFlags2Code = 0

	// QSQLModeCode is Q_SQL_MODE_CODE
	QSQLModeCode = 1

	// QCatalog is Q_CATALOG
	QCatalog = 2

	// QAutoIncrement is Q_AUTO_INCREMENT
	QAutoIncrement = 3

	// QCharsetCode is Q_CHARSET_CODE
	QCharsetCode = 4

	// QTimeZoneCode is Q_TIME_ZONE_CODE
	QTimeZoneCode = 5

	// QCatalogNZCode is Q_CATALOG_NZ_CODE
	QCatalogNZCode = 6
)

These constants describe the type of status variables in q Query packet.

View Source
const (
	// MaximumPositionSize is the maximum size of a
	// replication position. It is used as the maximum column size in the _vt.reparent_journal and
	// other related tables. A row has a maximum size of 65535 bytes. So
	// we want to stay under that. We use VARBINARY so the
	// character set doesn't matter, we only store ascii
	// characters anyway.
	MaximumPositionSize = 64000
)

Variables

View Source
var (
	// IntVarNames maps a InVar type to the variable name it represents.
	IntVarNames = map[byte]string{
		IntVarLastInsertID: "LAST_INSERT_ID",
		IntVarInsertID:     "INSERT_ID",
	}
)

Name of the variable represented by an IntVar.

View Source
var ZeroTimestamp = []byte("0000-00-00 00:00:00")

ZeroTimestamp is the special value 0 for a timestamp.

Functions

func CellValue

func CellValue(data []byte, pos int, typ byte, metadata uint16, styp querypb.Type) (sqltypes.Value, int, error)

CellValue returns the data for a cell as a sqltypes.Value, and how many bytes it takes. It only uses the querypb.Type value for the signed flag.

func EncodeGTID

func EncodeGTID(gtid GTID) string

EncodeGTID returns a string that contains both the flavor and value of the GTID, so that the correct parser can be selected when that string is passed to DecodeGTID.

func EncodePosition

func EncodePosition(rp Position) string

EncodePosition returns a string that contains both the flavor and value of the Position, so that the correct parser can be selected when that string is passed to DecodePosition.

Types

type BinlogEvent

type BinlogEvent interface {
	// IsValid returns true if the underlying data buffer contains a valid
	// event. This should be called first on any BinlogEvent, and other
	// methods should only be called if this one returns true. This ensures
	// you won't get panics due to bounds checking on the byte array.
	IsValid() bool

	// IsFormatDescription returns true if this is a
	// FORMAT_DESCRIPTION_EVENT. Do not call StripChecksum before
	// calling Format (Format returns the BinlogFormat anyway,
	// required for calling StripChecksum).
	IsFormatDescription() bool
	// IsQuery returns true if this is a QUERY_EVENT, which encompasses
	// all SQL statements.
	IsQuery() bool
	// IsXID returns true if this is an XID_EVENT, which is an alternate
	// form of COMMIT.
	IsXID() bool
	// IsGTID returns true if this is a GTID_EVENT.
	IsGTID() bool
	// IsRotate returns true if this is a ROTATE_EVENT.
	IsRotate() bool
	// IsIntVar returns true if this is an INTVAR_EVENT.
	IsIntVar() bool
	// IsRand returns true if this is a RAND_EVENT.
	IsRand() bool
	// IsPreviousGTIDs returns true if this event is a PREVIOUS_GTIDS_EVENT.
	IsPreviousGTIDs() bool

	// IsTableMapEvent returns true if this is a TABLE_MAP_EVENT.
	IsTableMap() bool
	// IsWriteRowsEvent returns true if this is a WRITE_ROWS_EVENT.
	IsWriteRows() bool
	// IsUpdateRowsEvent returns true if this is a UPDATE_ROWS_EVENT.
	IsUpdateRows() bool
	// IsDeleteRowsEvent returns true if this is a DELETE_ROWS_EVENT.
	IsDeleteRows() bool

	// Timestamp returns the timestamp from the event header.
	Timestamp() uint32

	// Format returns a BinlogFormat struct based on the event data.
	// This is only valid if IsFormatDescription() returns true.
	Format() (BinlogFormat, error)
	// GTID returns the GTID from the event, and if this event
	// also serves as a BEGIN statement.
	// This is only valid if IsGTID() returns true.
	GTID(BinlogFormat) (GTID, bool, error)
	// Query returns a Query struct representing data from a QUERY_EVENT.
	// This is only valid if IsQuery() returns true.
	Query(BinlogFormat) (Query, error)
	// IntVar returns the type and value of the variable for an INTVAR_EVENT.
	// This is only valid if IsIntVar() returns true.
	IntVar(BinlogFormat) (byte, uint64, error)
	// Rand returns the two seed values for a RAND_EVENT.
	// This is only valid if IsRand() returns true.
	Rand(BinlogFormat) (uint64, uint64, error)
	// PreviousGTIDs returns the Position from the event.
	// This is only valid if IsPreviousGTIDs() returns true.
	PreviousGTIDs(BinlogFormat) (Position, error)

	// TableID returns the table ID for a TableMap, UpdateRows,
	// WriteRows or DeleteRows event.
	TableID(BinlogFormat) uint64
	// TableMap returns a TableMap struct representing data from a
	// TABLE_MAP_EVENT.  This is only valid if IsTableMapEvent() returns
	// true.
	TableMap(BinlogFormat) (*TableMap, error)
	// Rows returns a Rows struct representing data from a
	// {WRITE,UPDATE,DELETE}_ROWS_EVENT.  This is only valid if
	// IsWriteRows(), IsUpdateRows(), or IsDeleteRows() returns
	// true.
	Rows(BinlogFormat, *TableMap) (Rows, error)

	// StripChecksum returns the checksum and a modified event with the
	// checksum stripped off, if any. If there is no checksum, it returns
	// the same event and a nil checksum.
	StripChecksum(BinlogFormat) (ev BinlogEvent, checksum []byte, err error)
}

BinlogEvent represents a single event from a raw MySQL binlog dump stream. The implementation is provided by each supported flavor in go/vt/mysqlctl.

binlog.Streamer receives these events through a mysqlctl.SlaveConnection and processes them, grouping statements into BinlogTransactions as appropriate.

Methods that only access header fields can't fail as long as IsValid() returns true, so they have a single return value. Methods that might fail even when IsValid() is true return an error value.

Methods that require information from the initial FORMAT_DESCRIPTION_EVENT will have a BinlogFormat parameter.

A BinlogEvent should never be sent over the wire. UpdateStream service will send BinlogTransactions from these events.

func NewDeleteRowsEvent

func NewDeleteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent

NewDeleteRowsEvent returns an DeleteRows event. Uses v2.

func NewFormatDescriptionEvent

func NewFormatDescriptionEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent

NewFormatDescriptionEvent creates a new FormatDescriptionEvent based on the provided BinlogFormat. It uses a mysql56BinlogEvent but could use a MariaDB one.

func NewIntVarEvent

func NewIntVarEvent(f BinlogFormat, s *FakeBinlogStream, typ byte, value uint64) BinlogEvent

NewIntVarEvent returns an IntVar event.

func NewInvalidEvent

func NewInvalidEvent() BinlogEvent

NewInvalidEvent returns an invalid event (its size is <19).

func NewInvalidFormatDescriptionEvent

func NewInvalidFormatDescriptionEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent

NewInvalidFormatDescriptionEvent returns an invalid FormatDescriptionEvent. The binlog version is set to 3. It IsValid() though.

func NewInvalidQueryEvent

func NewInvalidQueryEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent

NewInvalidQueryEvent returns an invalid QueryEvent. IsValid is however true. sqlPos is out of bounds.

func NewMariaDBGTIDEvent

func NewMariaDBGTIDEvent(f BinlogFormat, s *FakeBinlogStream, gtid MariadbGTID, hasBegin bool) BinlogEvent

NewMariaDBGTIDEvent returns a MariaDB specific GTID event. It ignores the Server in the gtid, instead uses the FakeBinlogStream.ServerID.

func NewMariadbBinlogEvent

func NewMariadbBinlogEvent(buf []byte) BinlogEvent

NewMariadbBinlogEvent creates a BinlogEvent instance from given byte array

func NewMysql56BinlogEvent

func NewMysql56BinlogEvent(buf []byte) BinlogEvent

NewMysql56BinlogEvent creates a BinlogEvent from given byte array

func NewQueryEvent

func NewQueryEvent(f BinlogFormat, s *FakeBinlogStream, q Query) BinlogEvent

NewQueryEvent makes up a QueryEvent based on the Query structure.

func NewRotateEvent

func NewRotateEvent(f BinlogFormat, s *FakeBinlogStream, position uint64, filename string) BinlogEvent

NewRotateEvent returns a RotateEvent. The timestmap of such an event should be zero, so we patch it in.

func NewTableMapEvent

func NewTableMapEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, tm *TableMap) BinlogEvent

NewTableMapEvent returns a TableMap event. Only works with post_header_length=8.

func NewUpdateRowsEvent

func NewUpdateRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent

NewUpdateRowsEvent returns an UpdateRows event. Uses v2.

func NewWriteRowsEvent

func NewWriteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent

NewWriteRowsEvent returns a WriteRows event. Uses v2.

func NewXIDEvent

func NewXIDEvent(f BinlogFormat, s *FakeBinlogStream) BinlogEvent

NewXIDEvent returns a XID event. We do not use the data, so keep it 0.

type BinlogFormat

type BinlogFormat struct {
	// FormatVersion is the version number of the binlog file format.
	// We only support version 4.
	FormatVersion uint16

	// ServerVersion is the name of the MySQL server version.
	// It starts with something like 5.6.33-xxxx.
	ServerVersion string

	// HeaderLength is the size in bytes of event headers other
	// than FORMAT_DESCRIPTION_EVENT. Almost always 19.
	HeaderLength byte

	// ChecksumAlgorithm is the ID number of the binlog checksum algorithm.
	// See three possible values below.
	ChecksumAlgorithm byte

	// HeaderSizes is an array of sizes of the headers for each message.
	HeaderSizes []byte
}

BinlogFormat contains relevant data from the FORMAT_DESCRIPTION_EVENT. This structure is passed to subsequent event types to let them know how to parse themselves.

func NewMariaDBBinlogFormat

func NewMariaDBBinlogFormat() BinlogFormat

NewMariaDBBinlogFormat returns a typical BinlogFormat for MariaDB 10.0.

func NewMySQL56BinlogFormat

func NewMySQL56BinlogFormat() BinlogFormat

NewMySQL56BinlogFormat returns a typical BinlogFormat for MySQL 5.6.

func (BinlogFormat) HeaderSize

func (f BinlogFormat) HeaderSize(typ byte) byte

HeaderSize returns the header size of any event type.

func (BinlogFormat) IsZero

func (f BinlogFormat) IsZero() bool

IsZero returns true if the BinlogFormat has not been initialized.

type Bitmap

type Bitmap struct {
	// contains filtered or unexported fields
}

Bitmap is used by the previous structures.

func NewServerBitmap

func NewServerBitmap(count int) Bitmap

NewServerBitmap returns a bitmap that can hold 'count' bits.

func (*Bitmap) Bit

func (b *Bitmap) Bit(index int) bool

Bit returned the value of a given bit in the Bitmap.

func (*Bitmap) BitCount

func (b *Bitmap) BitCount() int

BitCount returns how many bits are set in the bitmap. Note values that are not used may be set to 0 or 1, hence the non-efficient logic.

func (*Bitmap) Count

func (b *Bitmap) Count() int

Count returns the number of bits in this Bitmap.

func (*Bitmap) Set

func (b *Bitmap) Set(index int, value bool)

Set sets the given boolean value.

type FakeBinlogStream

type FakeBinlogStream struct {
	// ServerID is the server ID of the originating mysql-server.
	ServerID uint32

	// LogPosition is an incrementing log position.
	LogPosition uint32

	// Timestamp is a uint32 of when the events occur. It is not changed.
	Timestamp uint32
}

FakeBinlogStream is used to generate consistent BinlogEvent packets for a stream. It makes sure the ServerID and log positions are reasonable.

func NewFakeBinlogStream

func NewFakeBinlogStream() *FakeBinlogStream

NewFakeBinlogStream returns a simple FakeBinlogStream.

func (*FakeBinlogStream) Packetize

func (s *FakeBinlogStream) Packetize(f BinlogFormat, typ byte, flags uint16, data []byte) []byte

Packetize adds the binlog event header to a packet, and optionally the checksum.

type GTID

type GTID interface {
	// String returns the canonical printed form of the GTID as expected by a
	// particular flavor of MySQL.
	String() string

	// Flavor returns the key under which the corresponding GTID parser function
	// is registered in the gtidParsers map.
	Flavor() string

	// SourceServer returns the ID of the server that generated the transaction.
	SourceServer() interface{}

	// SequenceNumber returns the ID number that increases with each transaction.
	// It is only valid to compare the sequence numbers of two GTIDs if they have
	// the same domain value.
	SequenceNumber() interface{}

	// SequenceDomain returns the ID of the domain within which two sequence
	// numbers can be meaningfully compared.
	SequenceDomain() interface{}

	// GTIDSet returns a GTIDSet of the same flavor as this GTID, containing only
	// this GTID.
	GTIDSet() GTIDSet
}

GTID represents a Global Transaction ID, also known as Transaction Group ID. Each flavor of MySQL has its own format for the GTID. This interface is used along with various MysqlFlavor implementations to abstract the differences.

Types that implement GTID should use a non-pointer receiver. This ensures that comparing GTID interface values with == has the expected semantics.

func DecodeGTID

func DecodeGTID(s string) (GTID, error)

DecodeGTID converts a string in the format returned by EncodeGTID back into a GTID interface value with the correct underlying flavor.

func MustDecodeGTID

func MustDecodeGTID(s string) GTID

MustDecodeGTID calls DecodeGTID and panics on error.

func MustParseGTID

func MustParseGTID(flavor, value string) GTID

MustParseGTID calls ParseGTID and panics on error.

func ParseGTID

func ParseGTID(flavor, value string) (GTID, error)

ParseGTID calls the GTID parser for the specified flavor.

type GTIDSet

type GTIDSet interface {
	// String returns the canonical printed form of the set as expected by a
	// particular flavor of MySQL.
	String() string

	// Flavor returns the key under which the corresponding parser function is
	// registered in the transactionSetParsers map.
	Flavor() string

	// ContainsGTID returns true if the set contains the specified transaction.
	ContainsGTID(GTID) bool

	// Contains returns true if the set is a superset of another set.
	Contains(GTIDSet) bool

	// Equal returns true if the set is equal to another set.
	Equal(GTIDSet) bool

	// AddGTID returns a new GTIDSet that is expanded to contain the given GTID.
	AddGTID(GTID) GTIDSet
}

GTIDSet represents the set of transactions received or applied by a server. In some flavors, a single GTID is enough to specify the set of all transactions that came before it, but in others a more complex structure is required.

GTIDSet is wrapped by replication.Position, which is a concrete struct. When sending a GTIDSet over RPCs, encode/decode it as a string. Most code outside of this package should use replication.Position rather than GTIDSet.

type MariadbGTID

type MariadbGTID struct {
	// Domain is the ID number of the domain within which sequence numbers apply.
	Domain uint32
	// Server is the ID of the server that generated the transaction.
	Server uint32
	// Sequence is the sequence number of the transaction within the domain.
	Sequence uint64
}

MariadbGTID implements GTID.

func (MariadbGTID) AddGTID

func (gtid MariadbGTID) AddGTID(other GTID) GTIDSet

AddGTID implements GTIDSet.AddGTID().

func (MariadbGTID) Contains

func (gtid MariadbGTID) Contains(other GTIDSet) bool

Contains implements GTIDSet.Contains().

func (MariadbGTID) ContainsGTID

func (gtid MariadbGTID) ContainsGTID(other GTID) bool

ContainsGTID implements GTIDSet.ContainsGTID().

func (MariadbGTID) Equal

func (gtid MariadbGTID) Equal(other GTIDSet) bool

Equal implements GTIDSet.Equal().

func (MariadbGTID) Flavor

func (gtid MariadbGTID) Flavor() string

Flavor implements GTID.Flavor().

func (MariadbGTID) GTIDSet

func (gtid MariadbGTID) GTIDSet() GTIDSet

GTIDSet implements GTID.GTIDSet().

func (MariadbGTID) SequenceDomain

func (gtid MariadbGTID) SequenceDomain() interface{}

SequenceDomain implements GTID.SequenceDomain().

func (MariadbGTID) SequenceNumber

func (gtid MariadbGTID) SequenceNumber() interface{}

SequenceNumber implements GTID.SequenceNumber().

func (MariadbGTID) SourceServer

func (gtid MariadbGTID) SourceServer() interface{}

SourceServer implements GTID.SourceServer().

func (MariadbGTID) String

func (gtid MariadbGTID) String() string

String implements GTID.String().

type Mysql56GTID

type Mysql56GTID struct {
	// Server is the SID of the server that originally committed the transaction.
	Server SID
	// Sequence is the sequence number of the transaction within a given Server's
	// scope.
	Sequence int64
}

Mysql56GTID implements GTID

func (Mysql56GTID) Flavor

func (gtid Mysql56GTID) Flavor() string

Flavor implements GTID.Flavor().

func (Mysql56GTID) GTIDSet

func (gtid Mysql56GTID) GTIDSet() GTIDSet

GTIDSet implements GTID.GTIDSet().

func (Mysql56GTID) SequenceDomain

func (gtid Mysql56GTID) SequenceDomain() interface{}

SequenceDomain implements GTID.SequenceDomain().

func (Mysql56GTID) SequenceNumber

func (gtid Mysql56GTID) SequenceNumber() interface{}

SequenceNumber implements GTID.SequenceNumber().

func (Mysql56GTID) SourceServer

func (gtid Mysql56GTID) SourceServer() interface{}

SourceServer implements GTID.SourceServer().

func (Mysql56GTID) String

func (gtid Mysql56GTID) String() string

String implements GTID.String().

type Mysql56GTIDSet

type Mysql56GTIDSet map[SID][]interval

Mysql56GTIDSet implements GTIDSet for MySQL 5.6.

func NewMysql56GTIDSetFromSIDBlock

func NewMysql56GTIDSetFromSIDBlock(data []byte) (Mysql56GTIDSet, error)

NewMysql56GTIDSetFromSIDBlock builds a Mysql56GTIDSet from parsing a SID Block. This is the reverse of the SIDBlock method.

Expected format:

# bytes field
8       nSIDs

(nSIDs times)

16      SID
8       nIntervals

(nIntervals times)

8       start
8       end

func (Mysql56GTIDSet) AddGTID

func (set Mysql56GTIDSet) AddGTID(gtid GTID) GTIDSet

AddGTID implements GTIDSet.

func (Mysql56GTIDSet) Contains

func (set Mysql56GTIDSet) Contains(other GTIDSet) bool

Contains implements GTIDSet.

func (Mysql56GTIDSet) ContainsGTID

func (set Mysql56GTIDSet) ContainsGTID(gtid GTID) bool

ContainsGTID implements GTIDSet.

func (Mysql56GTIDSet) Equal

func (set Mysql56GTIDSet) Equal(other GTIDSet) bool

Equal implements GTIDSet.

func (Mysql56GTIDSet) Flavor

func (Mysql56GTIDSet) Flavor() string

Flavor implements GTIDSet.

func (Mysql56GTIDSet) SIDBlock

func (set Mysql56GTIDSet) SIDBlock() []byte

SIDBlock returns the binary encoding of a MySQL 5.6 GTID set as expected by internal commands that refer to an "SID block".

e.g. https://dev.mysql.com/doc/internals/en/com-binlog-dump-gtid.html

func (Mysql56GTIDSet) SIDs

func (set Mysql56GTIDSet) SIDs() []SID

SIDs returns a sorted list of SIDs in the set.

func (Mysql56GTIDSet) String

func (set Mysql56GTIDSet) String() string

String implements GTIDSet.

type Position

type Position struct {

	// GTIDSet is the underlying GTID set. It must not be anonymous,
	// or else Position would itself also implement the GTIDSet interface.
	GTIDSet GTIDSet
	// contains filtered or unexported fields
}

Position represents the information necessary to describe which transactions a server has seen, so that it can request a replication stream from a new master that picks up where it left off.

This must be a concrete struct because custom Unmarshalers can't be registered on an interface.

The == operator should not be used with Position, because the underlying GTIDSet might use slices, which are not comparable. Using == in those cases will result in a run-time panic.

func AppendGTID

func AppendGTID(rp Position, gtid GTID) Position

AppendGTID returns a new Position that represents the position after the given GTID is replicated.

func DecodePosition

func DecodePosition(s string) (rp Position, err error)

DecodePosition converts a string in the format returned by EncodePosition back into a Position value with the correct underlying flavor.

func MustParsePosition

func MustParsePosition(flavor, value string) Position

MustParsePosition calls ParsePosition and panics on error.

func ParsePosition

func ParsePosition(flavor, value string) (rp Position, err error)

ParsePosition calls the parser for the specified flavor.

func (Position) AtLeast

func (rp Position) AtLeast(other Position) bool

AtLeast returns true if this position is equal to or after another.

func (Position) Equal

func (rp Position) Equal(other Position) bool

Equal returns true if this position is equal to another.

func (Position) IsZero

func (rp Position) IsZero() bool

IsZero returns true if this is the zero value, Position{}.

func (Position) MarshalJSON

func (rp Position) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler.

func (Position) String

func (rp Position) String() string

String returns a string representation of the underlying GTIDSet. If the set is nil, it returns "<nil>" in the style of Sprintf("%v", nil).

func (*Position) UnmarshalJSON

func (rp *Position) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

type Query

type Query struct {
	Database string
	Charset  *binlogdatapb.Charset
	SQL      string
}

Query contains data from a QUERY_EVENT.

func (Query) String

func (q Query) String() string

String pretty-prints a Query.

type Row

type Row struct {
	// NullIdentifyColumns describes which of the identify columns are NULL.
	// It is only set for UPDATE and DELETE events.
	NullIdentifyColumns Bitmap

	// NullColumns describes which of the present columns are NULL.
	// It is only set for WRITE and UPDATE events.
	NullColumns Bitmap

	// Identify is the raw data for the columns used to identify a row.
	// It is only set for UPDATE and DELETE events.
	Identify []byte

	// Data is the raw data.
	// It is only set for WRITE and UPDATE events.
	Data []byte
}

Row contains data for a single Row in a Rows event.

type Rows

type Rows struct {
	// Flags has the flags from the event.
	Flags uint16

	// IdentifyColumns describes which columns are included to
	// identify the row. It is a bitmap indexed by the TableMap
	// list of columns.
	// Set for UPDATE and DELETE.
	IdentifyColumns Bitmap

	// DataColumns describes which columns are included. It is
	// a bitmap indexed by the TableMap list of columns.
	// Set for WRITE and UPDATE.
	DataColumns Bitmap

	// Rows is an array of Row in the event.
	Rows []Row
}

Rows contains data from a {WRITE,UPDATE,DELETE}_ROWS_EVENT.

func (*Rows) StringIdentifiesForTests

func (rs *Rows) StringIdentifiesForTests(tm *TableMap, rowIndex int) ([]string, error)

StringIdentifiesForTests is a helper method to return the string identify of all columns in a row in a Row. Only use it in tests, as the returned values cannot be interpreted correctly without the schema. We assume everything is unsigned in this method.

func (*Rows) StringValuesForTests

func (rs *Rows) StringValuesForTests(tm *TableMap, rowIndex int) ([]string, error)

StringValuesForTests is a helper method to return the string value of all columns in a row in a Row. Only use it in tests, as the returned values cannot be interpreted correctly without the schema. We assume everything is unsigned in this method.

type SID

type SID [16]byte

SID is the 16-byte unique ID of a MySQL 5.6 server.

func ParseSID

func ParseSID(s string) (sid SID, err error)

ParseSID parses an SID in the form used by MySQL 5.6.

func (SID) String

func (sid SID) String() string

String prints an SID in the form used by MySQL 5.6.

type TableMap

type TableMap struct {
	// Flags is the table's flags.
	Flags uint16

	// Database is the database name.
	Database string

	// Name is the name of the table.
	Name string

	// Types is an array of MySQL types for the fields.
	Types []byte

	// CanBeNull's bits are set if the column can be NULL.
	CanBeNull Bitmap

	// Metadata is an array of uint16, one per column.
	// It contains a few extra information about each column,
	// that is dependent on the type.
	// - If the metadata is not present, this is zero.
	// - If the metadata is one byte, only the lower 8 bits are used.
	// - If the metadata is two bytes, all 16 bits are used.
	Metadata []uint16
}

TableMap contains data from a TABLE_MAP_EVENT.

Jump to

Keyboard shortcuts

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