vtgateconn

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// VtgateProtocol defines the RPC implementation used for connecting to vtgate.
	VtgateProtocol = flag.String("vtgate_protocol", "grpc", "how to talk to vtgate")
)

Functions

func RegisterDialer

func RegisterDialer(name string, dialer DialerFunc)

RegisterDialer is meant to be used by Dialer implementations to self register.

Types

type DialerFunc

type DialerFunc func(ctx context.Context, address string) (Impl, error)

DialerFunc represents a function that will return an Impl object that can communicate with a VTGate.

type Impl

type Impl interface {
	// Execute executes a non-streaming query on vtgate. This is a V3 function.
	Execute(ctx context.Context, session *vtgatepb.Session, query string, bindVars map[string]*querypb.BindVariable) (*vtgatepb.Session, *sqltypes.Result, error)

	// ExecuteBatch executes a non-streaming queries on vtgate. This is a V3 function.
	ExecuteBatch(ctx context.Context, session *vtgatepb.Session, queryList []string, bindVarsList []map[string]*querypb.BindVariable) (*vtgatepb.Session, []sqltypes.QueryResponse, error)

	// StreamExecute executes a streaming query on vtgate. This is a V3 function.
	StreamExecute(ctx context.Context, session *vtgatepb.Session, query string, bindVars map[string]*querypb.BindVariable) (sqltypes.ResultStream, error)

	// ExecuteShards executes a non-streaming query for multiple shards on vtgate. This is a legacy function.
	ExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error)

	// ExecuteKeyspaceIds executes a non-streaming query for multiple keyspace_ids. This is a legacy function.
	ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error)

	// ExecuteKeyRanges executes a non-streaming query on a key range. This is a legacy function.
	ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error)

	// ExecuteEntityIds executes a non-streaming query for multiple entities. This is a legacy function.
	ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*vtgatepb.ExecuteEntityIdsRequest_EntityId, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, *sqltypes.Result, error)

	// ExecuteBatchShards executes a set of non-streaming queries for multiple shards. This is a legacy function.
	ExecuteBatchShards(ctx context.Context, queries []*vtgatepb.BoundShardQuery, tabletType topodatapb.TabletType, asTransaction bool, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, []sqltypes.Result, error)

	// ExecuteBatchKeyspaceIds executes a set of non-streaming queries for multiple keyspace ids. This is a legacy function.
	ExecuteBatchKeyspaceIds(ctx context.Context, queries []*vtgatepb.BoundKeyspaceIdQuery, tabletType topodatapb.TabletType, asTransaction bool, session *vtgatepb.Session, options *querypb.ExecuteOptions) (*vtgatepb.Session, []sqltypes.Result, error)

	// StreamExecuteShards executes a streaming query on vtgate, on a set of shards. This is a legacy function.
	StreamExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error)

	// StreamExecuteKeyRanges executes a streaming query on vtgate, on a set of keyranges. This is a legacy function.
	StreamExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error)

	// StreamExecuteKeyspaceIds executes a streaming query on vtgate, for the given keyspaceIds. This is a legacy function.
	StreamExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error)

	// Begin starts a transaction and returns a VTGateTX. This is a legacy function.
	Begin(ctx context.Context, singledb bool) (*vtgatepb.Session, error)
	// Commit commits the current transaction. This is a legacy function.
	Commit(ctx context.Context, session *vtgatepb.Session, twopc bool) error
	// Rollback rolls back the current transaction. This is a legacy function.
	Rollback(ctx context.Context, session *vtgatepb.Session) error

	// ResolveTransaction resolves the specified 2pc transaction.
	ResolveTransaction(ctx context.Context, dtid string) error

	// Messaging functions.
	MessageStream(ctx context.Context, keyspace string, shard string, keyRange *topodatapb.KeyRange, name string, callback func(*sqltypes.Result) error) error
	MessageAck(ctx context.Context, keyspace string, name string, ids []*querypb.Value) (int64, error)
	MessageAckKeyspaceIds(ctx context.Context, keyspace string, name string, idKeyspaceIDs []*vtgatepb.IdKeyspaceId) (int64, error)

	// GetSrvKeyspace returns a topo.SrvKeyspace.
	GetSrvKeyspace(ctx context.Context, keyspace string) (*topodatapb.SrvKeyspace, error)

	// VStream streams binlogevents
	VStream(ctx context.Context, tabletType topodatapb.TabletType, vgtid *binlogdatapb.VGtid, filter *binlogdatapb.Filter) (VStreamReader, error)

	// Close must be called for releasing resources.
	Close()
}

Impl defines the interface for a vtgate client protocol implementation. It can be used concurrently across goroutines.

type VStreamReader added in v1.0.1

type VStreamReader interface {
	// Recv returns the next result on the stream.
	// It will return io.EOF if the stream ended.
	Recv() ([]*binlogdatapb.VEvent, error)
}

VStreamReader is returned by VStream.

type VTGateConn

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

VTGateConn is the client API object to talk to vtgate. It is constructed using the Dial method. It supports legacy V2 APIs. It can be used concurrently. To access V3 functionality, use the Session function to create a VTGateSession objects.

func Dial

func Dial(ctx context.Context, address string) (*VTGateConn, error)

Dial dials using the command-line specified protocol, and returns the *VTGateConn.

func DialProtocol

func DialProtocol(ctx context.Context, protocol string, address string) (*VTGateConn, error)

DialProtocol dials a specific protocol, and returns the *VTGateConn

func (*VTGateConn) Begin

func (conn *VTGateConn) Begin(ctx context.Context) (*VTGateTx, error)

Begin starts a transaction and returns a VTGateTX.

func (*VTGateConn) Close

func (conn *VTGateConn) Close()

Close must be called for releasing resources.

func (*VTGateConn) ExecuteBatchKeyspaceIds

func (conn *VTGateConn) ExecuteBatchKeyspaceIds(ctx context.Context, queries []*vtgatepb.BoundKeyspaceIdQuery, tabletType topodatapb.TabletType, asTransaction bool, options *querypb.ExecuteOptions) ([]sqltypes.Result, error)

ExecuteBatchKeyspaceIds executes a set of non-streaming queries for multiple keyspace ids. If "asTransaction" is true, vtgate will automatically create a transaction (per shard) that encloses all the batch queries.

func (*VTGateConn) ExecuteBatchShards

func (conn *VTGateConn) ExecuteBatchShards(ctx context.Context, queries []*vtgatepb.BoundShardQuery, tabletType topodatapb.TabletType, asTransaction bool, options *querypb.ExecuteOptions) ([]sqltypes.Result, error)

ExecuteBatchShards executes a set of non-streaming queries for multiple shards. If "asTransaction" is true, vtgate will automatically create a transaction (per shard) that encloses all the batch queries.

func (*VTGateConn) ExecuteEntityIds

func (conn *VTGateConn) ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*vtgatepb.ExecuteEntityIdsRequest_EntityId, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

ExecuteEntityIds executes a non-streaming query for multiple entities.

func (*VTGateConn) ExecuteKeyRanges

func (conn *VTGateConn) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

ExecuteKeyRanges executes a non-streaming query on a key range.

func (*VTGateConn) ExecuteKeyspaceIds

func (conn *VTGateConn) ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

ExecuteKeyspaceIds executes a non-streaming query for multiple keyspace_ids.

func (*VTGateConn) ExecuteShards

func (conn *VTGateConn) ExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

ExecuteShards executes a non-streaming query for multiple shards on vtgate.

func (*VTGateConn) GetSrvKeyspace

func (conn *VTGateConn) GetSrvKeyspace(ctx context.Context, keyspace string) (*topodatapb.SrvKeyspace, error)

GetSrvKeyspace returns a topo.SrvKeyspace object.

func (*VTGateConn) MessageAck

func (conn *VTGateConn) MessageAck(ctx context.Context, keyspace string, name string, ids []*querypb.Value) (int64, error)

MessageAck acks messages.

func (*VTGateConn) MessageAckKeyspaceIds

func (conn *VTGateConn) MessageAckKeyspaceIds(ctx context.Context, keyspace string, name string, idKeyspaceIDs []*vtgatepb.IdKeyspaceId) (int64, error)

MessageAckKeyspaceIds is part of the vtgate service API. It routes message acks based on the associated keyspace ids.

func (*VTGateConn) MessageStream

func (conn *VTGateConn) MessageStream(ctx context.Context, keyspace string, shard string, keyRange *topodatapb.KeyRange, name string, callback func(*sqltypes.Result) error) error

MessageStream streams messages.

func (*VTGateConn) ResolveTransaction

func (conn *VTGateConn) ResolveTransaction(ctx context.Context, dtid string) error

ResolveTransaction resolves the 2pc transaction.

func (*VTGateConn) Session

func (conn *VTGateConn) Session(targetString string, options *querypb.ExecuteOptions) *VTGateSession

Session returns a VTGateSession that can be used to access V3 functions.

func (*VTGateConn) StreamExecuteKeyRanges

func (conn *VTGateConn) StreamExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error)

StreamExecuteKeyRanges executes a streaming query on vtgate, on a set of keyranges. It returns a ResultStream and an error. First check the error. Then you can pull values from the ResultStream until io.EOF, or another error.

func (*VTGateConn) StreamExecuteKeyspaceIds

func (conn *VTGateConn) StreamExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error)

StreamExecuteKeyspaceIds executes a streaming query on vtgate, for the given keyspaceIds. It returns a ResultStream and an error. First check the error. Then you can pull values from the ResultStream until io.EOF, or another error.

func (*VTGateConn) StreamExecuteShards

func (conn *VTGateConn) StreamExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error)

StreamExecuteShards executes a streaming query on vtgate, on a set of shards. It returns a ResultStream and an error. First check the error. Then you can pull values from the ResultStream until io.EOF, or another error.

func (*VTGateConn) VStream added in v1.0.1

func (conn *VTGateConn) VStream(ctx context.Context, tabletType topodatapb.TabletType, vgtid *binlogdatapb.VGtid, filter *binlogdatapb.Filter) (VStreamReader, error)

VStream streams binlog events.

type VTGateSession

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

VTGateSession exposes the V3 API to the clients. The object maintains client-side state and is comparable to a native MySQL connection. For example, if you enable autocommit on a Session object, all subsequent calls will respect this. Functions within an object must not be called concurrently. You can create as many objects as you want. All of them will share the underlying connection to vtgate ("VTGateConn" object).

func (*VTGateSession) Execute

func (sn *VTGateSession) Execute(ctx context.Context, query string, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error)

Execute performs a VTGate Execute.

func (*VTGateSession) ExecuteBatch

func (sn *VTGateSession) ExecuteBatch(ctx context.Context, query []string, bindVars []map[string]*querypb.BindVariable) ([]sqltypes.QueryResponse, error)

ExecuteBatch executes a list of queries on vtgate within the current transaction.

func (*VTGateSession) StreamExecute

func (sn *VTGateSession) StreamExecute(ctx context.Context, query string, bindVars map[string]*querypb.BindVariable) (sqltypes.ResultStream, error)

StreamExecute executes a streaming query on vtgate. It returns a ResultStream and an error. First check the error. Then you can pull values from the ResultStream until io.EOF, or another error.

type VTGateTx

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

VTGateTx defines an ongoing transaction. It should not be concurrently used across goroutines.

func (*VTGateTx) Commit

func (tx *VTGateTx) Commit(ctx context.Context) error

Commit commits the current transaction.

func (*VTGateTx) ExecuteBatchKeyspaceIds

func (tx *VTGateTx) ExecuteBatchKeyspaceIds(ctx context.Context, queries []*vtgatepb.BoundKeyspaceIdQuery, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) ([]sqltypes.Result, error)

ExecuteBatchKeyspaceIds executes a set of non-streaming queries for multiple keyspace ids.

func (*VTGateTx) ExecuteBatchShards

func (tx *VTGateTx) ExecuteBatchShards(ctx context.Context, queries []*vtgatepb.BoundShardQuery, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) ([]sqltypes.Result, error)

ExecuteBatchShards executes a set of non-streaming queries for multiple shards.

func (*VTGateTx) ExecuteEntityIds

func (tx *VTGateTx) ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*vtgatepb.ExecuteEntityIdsRequest_EntityId, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

ExecuteEntityIds executes a non-streaming query for multiple entities.

func (*VTGateTx) ExecuteKeyRanges

func (tx *VTGateTx) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

ExecuteKeyRanges executes a non-streaming query on a key range.

func (*VTGateTx) ExecuteKeyspaceIds

func (tx *VTGateTx) ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

ExecuteKeyspaceIds executes a non-streaming query for multiple keyspace_ids.

func (*VTGateTx) ExecuteShards

func (tx *VTGateTx) ExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

ExecuteShards executes a query for multiple shards on vtgate within the current transaction.

func (*VTGateTx) Rollback

func (tx *VTGateTx) Rollback(ctx context.Context) error

Rollback rolls back the current transaction.

Jump to

Keyboard shortcuts

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