go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/binlog/binlogplayer Index | Files

package binlogplayer

import "gopkg.in/src-d/go-vitess.v1/vt/binlog/binlogplayer"

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

Index

Package Files

binlog_player.go client.go dbclient.go fake_dbclient.go mock_dbclient.go

Variables

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"

    // VReplicationInit is for the Init state.
    VReplicationInit = "Init"
    // VReplicationCopying is for the Copying state.
    VReplicationCopying = "Copying"
    // BlpRunning is for the Running state.
    BlpRunning = "Running"
    // BlpStopped is for the Stopped state.
    BlpStopped = "Stopped"
    // BlpError is for the Error state.
    BlpError = "Error"
)

func AlterVReplicationTable Uses

func AlterVReplicationTable() []string

AlterVReplicationTable adds new columns to vreplication table

func CreateVReplication Uses

func CreateVReplication(workflow string, source *binlogdatapb.BinlogSource, position string, maxTPS, maxReplicationLag, timeUpdated int64, dbName string) string

CreateVReplication returns a statement to populate the first value into the _vt.vreplication table.

func CreateVReplicationState Uses

func CreateVReplicationState(workflow string, source *binlogdatapb.BinlogSource, position, state string, dbName string) string

CreateVReplicationState returns a statement to create a stopped vreplication.

func CreateVReplicationTable Uses

func CreateVReplicationTable() []string

CreateVReplicationTable returns the statements required to create the _vt.vreplication table. id: is an auto-increment column that identifies the stream. workflow: documents the creator/manager of the stream. Example: 'SplitClone'. source: contains a string proto representation of binlogpb.BinlogSource. pos: initially, a start position, and is updated to the current position by the binlog player. stop_pos: optional column that specifies the stop position. max_tps: max transactions per second. max_replication_lag: if replication lag exceeds this amount writing is throttled accordingly. cell: optional column that overrides the current cell to replicate from. tablet_types: optional column that overrides the tablet types to look to replicate from. time_update: last time an event was applied. transaction_timestamp: timestamp of the transaction (from the master). state: Running, Error or Stopped. message: Reason for current state.

func DeleteVReplication Uses

func DeleteVReplication(uid uint32) string

DeleteVReplication returns a statement to delete the replication.

func GenerateUpdatePos Uses

func GenerateUpdatePos(uid uint32, pos mysql.Position, timeUpdated int64, txTimestamp int64) string

GenerateUpdatePos returns a statement to update a value in the _vt.vreplication table.

func ReadVReplicationPos Uses

func ReadVReplicationPos(index uint32) string

ReadVReplicationPos returns a statement to query the gtid for a given stream from the _vt.vreplication table.

func ReadVReplicationStatus Uses

func ReadVReplicationStatus(index uint32) string

ReadVReplicationStatus returns a statement to query the status fields for a given stream from the _vt.vreplication table.

func RegisterClientFactory Uses

func RegisterClientFactory(name string, factory ClientFactory)

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

func SetVReplicationState Uses

func SetVReplicationState(dbClient DBClient, uid uint32, state, message string) error

SetVReplicationState updates the state in the _vt.vreplication table.

func StartVReplication Uses

func StartVReplication(uid uint32) string

StartVReplication returns a statement to start the replication.

func StartVReplicationUntil Uses

func StartVReplicationUntil(uid uint32, pos string) string

StartVReplicationUntil returns a statement to start the replication with a stop position.

func StopVReplication Uses

func StopVReplication(uid uint32, message string) string

StopVReplication returns a statement to stop the replication.

type BinlogPlayer Uses

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

BinlogPlayer is for reading a stream of updates from BinlogServer.

func NewBinlogPlayerKeyRange Uses

func NewBinlogPlayerKeyRange(dbClient DBClient, tablet *topodatapb.Tablet, keyRange *topodatapb.KeyRange, uid uint32, blplStats *Stats) *BinlogPlayer

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

func NewBinlogPlayerTables Uses

func NewBinlogPlayerTables(dbClient DBClient, tablet *topodatapb.Tablet, tables []string, uid uint32, blplStats *Stats) *BinlogPlayer

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

func (*BinlogPlayer) ApplyBinlogEvents Uses

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

ApplyBinlogEvents makes an RPC request to BinlogServer and processes the events. It returns nil if the provided context was canceled, or if we reached the stopping point. If an error is encountered, it updates the vreplication state to "Error". If a stop position was specifed, and reached, the state is updated to "Stopped".

type BinlogTransactionStream Uses

type BinlogTransactionStream interface {
    // Recv returns the next BinlogTransaction, or an error if the RPC was
    // interrupted.
    Recv() (*binlogdatapb.BinlogTransaction, error)
}

BinlogTransactionStream is the interface of the object returned by StreamTables and StreamKeyRange

type Client Uses

type Client interface {
    // Dial a server
    Dial(tablet *topodatapb.Tablet) error

    // Close the connection
    Close()

    // 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 *binlogdatapb.Charset) (BinlogTransactionStream, 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, keyRange *topodatapb.KeyRange, charset *binlogdatapb.Charset) (BinlogTransactionStream, error)
}

Client is the interface all clients must satisfy

type ClientFactory Uses

type ClientFactory func() Client

ClientFactory is the factory method to create a Client

type DBClient Uses

type DBClient interface {
    DBName() string
    Connect() error
    Begin() error
    Commit() error
    Rollback() error
    Close()
    ExecuteFetch(query string, maxrows int) (qr *sqltypes.Result, err error)
}

DBClient is a high level interface to the database.

func NewDBClient Uses

func NewDBClient(params *mysql.ConnParams) DBClient

NewDBClient creates a DBClient instance

func NewFakeDBClient Uses

func NewFakeDBClient() DBClient

NewFakeDBClient returns a fake DBClient. Its functions return preset responses to requests.

type MockDBClient Uses

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

MockDBClient mocks a DBClient. It must be configured to expect requests in a specific order.

func NewMockDBClient Uses

func NewMockDBClient(t *testing.T) *MockDBClient

NewMockDBClient returns a new DBClientMock.

func (*MockDBClient) Begin Uses

func (dc *MockDBClient) Begin() error

Begin is part of the DBClient interface

func (*MockDBClient) Close Uses

func (dc *MockDBClient) Close()

Close is part of the DBClient interface

func (*MockDBClient) Commit Uses

func (dc *MockDBClient) Commit() error

Commit is part of the DBClient interface

func (*MockDBClient) Connect Uses

func (dc *MockDBClient) Connect() error

Connect is part of the DBClient interface

func (*MockDBClient) DBName Uses

func (dc *MockDBClient) DBName() string

DBName is part of the DBClient interface

func (*MockDBClient) ExecuteFetch Uses

func (dc *MockDBClient) ExecuteFetch(query string, maxrows int) (qr *sqltypes.Result, err error)

ExecuteFetch is part of the DBClient interface

func (*MockDBClient) ExpectRequest Uses

func (dc *MockDBClient) ExpectRequest(query string, result *sqltypes.Result, err error)

ExpectRequest adds an expected result to the mock. This function should not be called conncurrently with other commands.

func (*MockDBClient) ExpectRequestRE Uses

func (dc *MockDBClient) ExpectRequestRE(queryRE string, result *sqltypes.Result, err error)

ExpectRequestRE adds an expected result to the mock. queryRE is a regular expression. This function should not be called conncurrently with other commands.

func (*MockDBClient) Rollback Uses

func (dc *MockDBClient) Rollback() error

Rollback is part of the DBClient interface

func (*MockDBClient) Wait Uses

func (dc *MockDBClient) Wait()

Wait waits for all expected requests to be executed. dc.t.Fatalf is executed on 1 second timeout. Wait should not be called concurrently with ExpectRequest.

type Stats Uses

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

    SecondsBehindMaster sync2.AtomicInt64
    History             *history.History
    // contains filtered or unexported fields
}

Stats 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 NewStats Uses

func NewStats() *Stats

NewStats creates a new Stats structure.

func (*Stats) LastPosition Uses

func (bps *Stats) LastPosition() mysql.Position

LastPosition gets the last replication position.

func (*Stats) MessageHistory Uses

func (bps *Stats) MessageHistory() []string

MessageHistory gets all the messages, we store 3 at a time

func (*Stats) SetLastPosition Uses

func (bps *Stats) SetLastPosition(pos mysql.Position)

SetLastPosition sets the last replication position.

type StatsHistoryRecord Uses

type StatsHistoryRecord struct {
    Time    time.Time
    Message string
}

StatsHistoryRecord is used to store a Message with timestamp

func (*StatsHistoryRecord) IsDuplicate Uses

func (r *StatsHistoryRecord) IsDuplicate(other interface{}) bool

IsDuplicate implements history.Deduplicable

type VRSettings Uses

type VRSettings struct {
    StartPos          mysql.Position
    StopPos           mysql.Position
    MaxTPS            int64
    MaxReplicationLag int64
    State             string
}

VRSettings contains the settings of a vreplication table.

func ReadVRSettings Uses

func ReadVRSettings(dbClient DBClient, uid uint32) (VRSettings, error)

ReadVRSettings retrieves the throttler settings for vreplication from the checkpoint table.

Package binlogplayer imports 22 packages (graph) and is imported by 10 packages. Updated 2019-06-13. Refresh now. Tools for package owners.