proto

package
v2.0.0-alpha5+incompat... Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2015 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BL_UNRECOGNIZED = iota
	BL_BEGIN
	BL_COMMIT
	BL_ROLLBACK
	BL_DML
	BL_DDL
	BL_SET
)

Valid statement types in the binlogs.

Variables

View Source
var BL_CATEGORY_NAMES = map[int]string{
	BL_UNRECOGNIZED: "BL_UNRECOGNIZED",
	BL_BEGIN:        "BL_BEGIN",
	BL_COMMIT:       "BL_COMMIT",
	BL_ROLLBACK:     "BL_ROLLBACK",
	BL_DML:          "BL_DML",
	BL_DDL:          "BL_DDL",
	BL_SET:          "BL_SET",
}

Functions

func BinlogTransactionToProto

func BinlogTransactionToProto(bt *BinlogTransaction) *pb.BinlogTransaction

BinlogTransactionToProto converts a BinlogTransaction to a proto3

func BlpPositionListToProto

func BlpPositionListToProto(l *BlpPositionList) []*pbt.BlpPosition

BlpPositionListToProto converts a BlpPositionList to a proto3

func BlpPositionToProto

func BlpPositionToProto(b *BlpPosition) *pbt.BlpPosition

BlpPositionToProto converts a BlpPosition to a proto3

func StatementToProto

func StatementToProto(s *Statement) *pb.BinlogTransaction_Statement

StatementToProto converts a Statement to a proto3

func StreamEventToProto

func StreamEventToProto(s *StreamEvent) *pb.StreamEvent

StreamEventToProto converts a StreamEvent to a proto3

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.
	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
	// HasGTID returns true if this event contains a GTID. That could either be
	// because it's a GTID_EVENT (MariaDB, MySQL 5.6), or because it is some
	// arbitrary event type that has a GTID in the header (Google MySQL).
	HasGTID(BinlogFormat) 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.
	// This is only valid if HasGTID() returns true.
	GTID(BinlogFormat) (myproto.GTID, error)
	// IsBeginGTID returns true if this is a GTID_EVENT that also serves as a
	// BEGIN statement. Otherwise, the GTID_EVENT is just providing the GTID for
	// the following QUERY_EVENT.
	// This is only valid if IsGTID() returns true.
	IsBeginGTID(BinlogFormat) bool
	// 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 name and value of the variable for an INTVAR_EVENT.
	// This is only valid if IsIntVar() returns true.
	IntVar(BinlogFormat) (string, 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)

	// 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.

BinlogStreamer 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.

type BinlogFormat

type BinlogFormat struct {
	// FormatVersion is the version number of the binlog file format.
	FormatVersion uint16
	// ServerVersion is the name of the MySQL server version.
	ServerVersion string
	// HeaderLength is the size in bytes of event headers other than FORMAT_DESCRIPTION_EVENT.
	HeaderLength byte
	// ChecksumAlgorithm is the ID number of the binlog checksum algorithm.
	ChecksumAlgorithm 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 (BinlogFormat) IsZero

func (f BinlogFormat) IsZero() bool

IsZero returns true if the BinlogFormat has not been initialized.

type BinlogTransaction

type BinlogTransaction struct {
	Statements    []Statement
	Timestamp     int64
	TransactionID string
}

BinlogTransaction represents one transaction as read from the binlog. Timestamp is set if the first statement was something like 'SET TIMESTAMP=...'

func ProtoToBinlogTransaction

func ProtoToBinlogTransaction(bt *pb.BinlogTransaction) *BinlogTransaction

ProtoToBinlogTransaction converts a proto to a BinlogTransaction

func (*BinlogTransaction) MarshalBson

func (binlogTransaction *BinlogTransaction) MarshalBson(buf *bytes2.ChunkedWriter, key string)

MarshalBson bson-encodes BinlogTransaction.

func (*BinlogTransaction) UnmarshalBson

func (binlogTransaction *BinlogTransaction) UnmarshalBson(buf *bytes.Buffer, kind byte)

UnmarshalBson bson-decodes into BinlogTransaction.

type BlpPosition

type BlpPosition struct {
	Uid      uint32
	Position myproto.ReplicationPosition
}

BlpPosition describes a binlog player position to start from.

func ProtoToBlpPosition

func ProtoToBlpPosition(b *pbt.BlpPosition) *BlpPosition

ProtoToBlpPosition converts a proto to a BlpPosition

func (*BlpPosition) MarshalBson

func (blpPosition *BlpPosition) MarshalBson(buf *bytes2.ChunkedWriter, key string)

MarshalBson bson-encodes BlpPosition.

func (*BlpPosition) UnmarshalBson

func (blpPosition *BlpPosition) UnmarshalBson(buf *bytes.Buffer, kind byte)

UnmarshalBson bson-decodes into BlpPosition.

type BlpPositionList

type BlpPositionList struct {
	Entries []BlpPosition
}

BlpPositionList is a list of BlpPosition, not sorted.

func ProtoToBlpPositionList

func ProtoToBlpPositionList(l []*pbt.BlpPosition) *BlpPositionList

ProtoToBlpPositionList converts a proto to a BlpPositionList

func (*BlpPositionList) FindBlpPositionById

func (bpl *BlpPositionList) FindBlpPositionById(id uint32) (*BlpPosition, error)

FindBlpPositionById returns the BlpPosition with the given id, or error

func (*BlpPositionList) MarshalBson

func (blpPositionList *BlpPositionList) MarshalBson(buf *bytes2.ChunkedWriter, key string)

MarshalBson bson-encodes BlpPositionList.

func (*BlpPositionList) UnmarshalBson

func (blpPositionList *BlpPositionList) UnmarshalBson(buf *bytes.Buffer, kind byte)

UnmarshalBson bson-decodes into BlpPositionList.

type KeyRangeRequest

type KeyRangeRequest struct {
	Position       string
	KeyspaceIdType key.KeyspaceIdType
	KeyRange       key.KeyRange
	Charset        *mproto.Charset
}

KeyRangeRequest is used to make a request for StreamKeyRange.

type Query

type Query struct {
	Database string
	Charset  *mproto.Charset
	Sql      string
}

Query contains data from a QUERY_EVENT.

func (Query) String

func (q Query) String() string

String pretty-prints a Query.

type Statement

type Statement struct {
	Category int
	Charset  *mproto.Charset
	Sql      string
}

Statement represents one statement as read from the binlog.

func ProtoToStatement

func ProtoToStatement(s *pb.BinlogTransaction_Statement) Statement

ProtoToStatement converts a proto to a Statement

func (*Statement) MarshalBson

func (statement *Statement) MarshalBson(buf *bytes2.ChunkedWriter, key string)

MarshalBson bson-encodes Statement.

func (Statement) String

func (s Statement) String() string

String pretty-prints a statement.

func (*Statement) UnmarshalBson

func (statement *Statement) UnmarshalBson(buf *bytes.Buffer, kind byte)

UnmarshalBson bson-decodes into Statement.

type StreamEvent

type StreamEvent struct {
	// Category can be "DML", "DDL", "ERR" or "POS"
	Category string

	// TableName, PrimaryKeyFields and PrimaryKeyValues are set for DML
	TableName        string
	PrimaryKeyFields []mproto.Field
	PrimaryKeyValues [][]sqltypes.Value

	// Sql is set for DDL or ERR
	Sql string

	// Timestamp is set for DML, DDL or ERR
	Timestamp int64

	// TransactionID is set for POS
	TransactionID string
}

StreamEvent represents one event for the update stream.

func ProtoToStreamEvent

func ProtoToStreamEvent(s *pb.StreamEvent) *StreamEvent

ProtoToStreamEvent converts a proto to a StreamEvent

func (*StreamEvent) MarshalBson

func (streamEvent *StreamEvent) MarshalBson(buf *bytes2.ChunkedWriter, key string)

MarshalBson bson-encodes StreamEvent.

func (*StreamEvent) UnmarshalBson

func (streamEvent *StreamEvent) UnmarshalBson(buf *bytes.Buffer, kind byte)

UnmarshalBson bson-decodes into StreamEvent.

type TablesRequest

type TablesRequest struct {
	Position string
	Tables   []string
	Charset  *mproto.Charset
}

TablesRequest is used to make a request for StreamTables.

type UpdateStream

type UpdateStream interface {
	// ServeUpdateStream serves the query and streams the result
	// for the full update stream
	ServeUpdateStream(position string, sendReply func(reply *StreamEvent) error) error

	// StreamKeyRange streams events related to a KeyRange only
	StreamKeyRange(position string, keyspaceIdType key.KeyspaceIdType, keyRange *pb.KeyRange, charset *mproto.Charset, sendReply func(reply *BinlogTransaction) error) error

	// StreamTables streams events related to a set of Tables only
	StreamTables(position string, tables []string, charset *mproto.Charset, sendReply func(reply *BinlogTransaction) error) error

	// HandlePanic should be called in a defer,
	// first thing in the RPC implementation.
	HandlePanic(*error)
}

UpdateStream is the interface for the server

type UpdateStreamRequest

type UpdateStreamRequest struct {
	Position string
}

UpdateStreamRequest is used to make a request for ServeUpdateStream.

Jump to

Keyboard shortcuts

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