binlogplayer

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

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

Go to latest
Published: Aug 28, 2015 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package binlogplayer contains the code that plays a filtered replication stream on a client database. It usually runs inside the destination master vttablet process.

Index

Constants

This section is empty.

Variables

View Source
var (
	// SlowQueryThreshold will cause we logging anything that's higher than it.
	SlowQueryThreshold = time.Duration(100 * time.Millisecond)

	// BlplQuery is the key for the stats map.
	BlplQuery = "Query"
	// BlplTransaction is the key for the stats map.
	BlplTransaction = "Transaction"

	// BlpFlagDontStart means don't start a BinlogPlayer
	BlpFlagDontStart = "DontStart"
)

Functions

func CreateBlpCheckpoint

func CreateBlpCheckpoint() []string

CreateBlpCheckpoint returns the statements required to create the _vt.blp_checkpoint table

func PopulateBlpCheckpoint

func PopulateBlpCheckpoint(index uint32, pos myproto.ReplicationPosition, timeUpdated int64, flags string) string

PopulateBlpCheckpoint returns a statement to populate the first value into the _vt.blp_checkpoint table.

func QueryBlpCheckpoint

func QueryBlpCheckpoint(index uint32) string

QueryBlpCheckpoint returns a statement to query the gtid and flags for a given shard from the _vt.blp_checkpoint table.

func ReadStartPosition

func ReadStartPosition(dbClient VtClient, uid uint32) (*proto.BlpPosition, string, error)

ReadStartPosition will return the current start position and the flags for the provided binlog player.

func RegisterClientFactory

func RegisterClientFactory(name string, factory ClientFactory)

RegisterClientFactory adds a new factory. Call during init().

func UpdateBlpCheckpoint

func UpdateBlpCheckpoint(uid uint32, pos myproto.ReplicationPosition, timeUpdated int64, txTimestamp int64) string

UpdateBlpCheckpoint returns a statement to update a value in the _vt.blp_checkpoint table.

Types

type BinlogPlayer

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

BinlogPlayer is handling reading a stream of updates from BinlogServer

func NewBinlogPlayerKeyRange

func NewBinlogPlayerKeyRange(dbClient VtClient, endPoint *pb.EndPoint, keyspaceIdType pb.KeyspaceIdType, keyRange *pb.KeyRange, startPosition *proto.BlpPosition, stopPosition myproto.ReplicationPosition, blplStats *BinlogPlayerStats) *BinlogPlayer

NewBinlogPlayerKeyRange returns a new BinlogPlayer pointing at the server replicating the provided keyrange, starting at the startPosition, and updating _vt.blp_checkpoint with uid=startPosition.Uid. If !stopPosition.IsZero(), it will stop when reaching that position.

func NewBinlogPlayerTables

func NewBinlogPlayerTables(dbClient VtClient, endPoint *pb.EndPoint, tables []string, startPosition *proto.BlpPosition, stopPosition myproto.ReplicationPosition, blplStats *BinlogPlayerStats) *BinlogPlayer

NewBinlogPlayerTables returns a new BinlogPlayer pointing at the server replicating the provided tables, starting at the startPosition, and updating _vt.blp_checkpoint with uid=startPosition.Uid. If !stopPosition.IsZero(), it will stop when reaching that position.

func (*BinlogPlayer) ApplyBinlogEvents

func (blp *BinlogPlayer) ApplyBinlogEvents(ctx context.Context) error

ApplyBinlogEvents makes an RPC request to BinlogServer and processes the events. It will return nil if the provided context was canceled, or if we reached the stopping point. It will return io.EOF if the server stops sending us updates. It may return any other error it encounters.

type BinlogPlayerStats

type BinlogPlayerStats struct {
	// Stats about the player, keys used are BlplQuery and BlplTransaction
	Timings *stats.Timings
	Rates   *stats.Rates

	SecondsBehindMaster sync2.AtomicInt64
	// contains filtered or unexported fields
}

BinlogPlayerStats is the internal stats of a player. It is a different structure that is passed in so stats can be collected over the life of multiple individual players.

func NewBinlogPlayerStats

func NewBinlogPlayerStats() *BinlogPlayerStats

NewBinlogPlayerStats creates a new BinlogPlayerStats structure

func (*BinlogPlayerStats) GetLastPosition

func (bps *BinlogPlayerStats) GetLastPosition() myproto.ReplicationPosition

GetLastPosition gets the last replication position.

func (*BinlogPlayerStats) SetLastPosition

func (bps *BinlogPlayerStats) SetLastPosition(pos myproto.ReplicationPosition)

SetLastPosition sets the last replication position.

type Client

type Client interface {
	// Dial a server
	Dial(endPoint *pb.EndPoint, connTimeout time.Duration) error

	// Close the connection
	Close()

	// Ask the server to stream binlog updates.
	// Should return context.Canceled if the context is canceled.
	ServeUpdateStream(ctx context.Context, position string) (chan *proto.StreamEvent, ErrFunc, error)

	// Ask the server to stream updates related to the provided tables.
	// Should return context.Canceled if the context is canceled.
	StreamTables(ctx context.Context, position string, tables []string, charset *mproto.Charset) (chan *proto.BinlogTransaction, ErrFunc, error)

	// Ask the server to stream updates related to the provided keyrange.
	// Should return context.Canceled if the context is canceled.
	StreamKeyRange(ctx context.Context, position string, keyspaceIdType key.KeyspaceIdType, keyRange *pb.KeyRange, charset *mproto.Charset) (chan *proto.BinlogTransaction, ErrFunc, error)
}

Client is the interface all clients must satisfy

type ClientFactory

type ClientFactory func() Client

ClientFactory is the factory method to create a Client

type DBClient

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

DBClient is a real VtClient backed by a mysql connection

func NewDbClient

func NewDbClient(params *sqldb.ConnParams) *DBClient

NewDbClient creates a DBClient instance

func (*DBClient) Begin

func (dc *DBClient) Begin() error

Begin starts a transaction

func (*DBClient) Close

func (dc *DBClient) Close()

Close closes connection to the db server

func (*DBClient) Commit

func (dc *DBClient) Commit() error

Commit commits the current transaction

func (*DBClient) Connect

func (dc *DBClient) Connect() error

Connect connects to a db server

func (*DBClient) ExecuteFetch

func (dc *DBClient) ExecuteFetch(query string, maxrows int, wantfields bool) (*mproto.QueryResult, error)

ExecuteFetch sends query to the db server and fetch the result

func (*DBClient) Rollback

func (dc *DBClient) Rollback() error

Rollback rollbacks the current transaction

type DummyVtClient

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

DummyVtClient is a VtClient that writes to a writer instead of executing anything

func NewDummyVtClient

func NewDummyVtClient() *DummyVtClient

func (DummyVtClient) Begin

func (dc DummyVtClient) Begin() error

func (DummyVtClient) Close

func (dc DummyVtClient) Close()

func (DummyVtClient) Commit

func (dc DummyVtClient) Commit() error

func (DummyVtClient) Connect

func (dc DummyVtClient) Connect() error

func (DummyVtClient) ExecuteFetch

func (dc DummyVtClient) ExecuteFetch(query string, maxrows int, wantfields bool) (qr *mproto.QueryResult, err error)

func (DummyVtClient) Rollback

func (dc DummyVtClient) Rollback() error

type ErrFunc

type ErrFunc func() error

ErrFunc is a return value for streaming events

type VtClient

type VtClient interface {
	Connect() error
	Begin() error
	Commit() error
	Rollback() error
	Close()
	ExecuteFetch(query string, maxrows int, wantfields bool) (qr *mproto.QueryResult, err error)
}

VtClient is a high level interface to the database

Jump to

Keyboard shortcuts

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