Documentation ¶
Overview ¶
Package vtgate provides query routing rpc services for vttablets.
Index ¶
- func Init(blm *BalancerMap, tabletProtocol string, retryDelay time.Duration, ...)
- func RegisterDialer(name string, dialer TabletDialer)
- type Balancer
- type BalancerMap
- type ErrFunc
- type GetAddressesFunc
- type ScatterConn
- func (stc *ScatterConn) Begin() error
- func (stc *ScatterConn) Close() error
- func (stc *ScatterConn) Commit() (err error)
- func (stc *ScatterConn) Execute(query string, bindVars map[string]interface{}, keyspace string, ...) (*mproto.QueryResult, error)
- func (stc *ScatterConn) ExecuteBatch(queries []proto.BoundQuery, keyspace string, shards []string) (qrs *tproto.QueryResultList, err error)
- func (stc *ScatterConn) Rollback() (err error)
- func (stc *ScatterConn) StreamExecute(query string, bindVars map[string]interface{}, keyspace string, ...) error
- func (stc *ScatterConn) TransactionId() int64
- type ShardConn
- func (sdc *ShardConn) Begin() (err error)
- func (sdc *ShardConn) Close() error
- func (sdc *ShardConn) Commit() (err error)
- func (sdc *ShardConn) Execute(query string, bindVars map[string]interface{}) (qr *mproto.QueryResult, err error)
- func (sdc *ShardConn) ExecuteBatch(queries []proto.BoundQuery) (qrs *tproto.QueryResultList, err error)
- func (sdc *ShardConn) Rollback() (err error)
- func (sdc *ShardConn) StreamExecute(query string, bindVars map[string]interface{}) (results <-chan *mproto.QueryResult, errFunc ErrFunc)
- func (sdc *ShardConn) TransactionId() int64
- func (sdc *ShardConn) WrapError(in error) (wrapped error)
- type SubsetTopoServ
- type TabletBson
- func (conn *TabletBson) Begin() error
- func (conn *TabletBson) Close() error
- func (conn *TabletBson) Commit() error
- func (conn *TabletBson) Execute(query string, bindVars map[string]interface{}) (*mproto.QueryResult, error)
- func (conn *TabletBson) ExecuteBatch(queries []proto.BoundQuery) (*tproto.QueryResultList, error)
- func (conn *TabletBson) Rollback() error
- func (conn *TabletBson) StreamExecute(query string, bindVars map[string]interface{}) (<-chan *mproto.QueryResult, ErrFunc)
- func (conn *TabletBson) TransactionId() int64
- type TabletConn
- type TabletDialer
- type VTGate
- func (vtg *VTGate) Begin(context *rpcproto.Context, session *proto.Session, noOutput *string) error
- func (vtg *VTGate) CloseSession(context *rpcproto.Context, session *proto.Session, noOutput *string) error
- func (vtg *VTGate) Commit(context *rpcproto.Context, session *proto.Session, noOutput *string) error
- func (vtg *VTGate) ExecuteBatchShard(context *rpcproto.Context, batchQuery *proto.BatchQueryShard, ...) error
- func (vtg *VTGate) ExecuteShard(context *rpcproto.Context, query *proto.QueryShard, reply *mproto.QueryResult) error
- func (vtg *VTGate) GetSessionId(sessionParams *proto.SessionParams, session *proto.Session) error
- func (vtg *VTGate) Rollback(context *rpcproto.Context, session *proto.Session, noOutput *string) error
- func (vtg *VTGate) StreamExecuteShard(context *rpcproto.Context, query *proto.QueryShard, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(blm *BalancerMap, tabletProtocol string, retryDelay time.Duration, retryCount int)
func RegisterDialer ¶
func RegisterDialer(name string, dialer TabletDialer)
Types ¶
type Balancer ¶
type Balancer struct {
// contains filtered or unexported fields
}
Balancer is a simple round-robin load balancer. It allows you to temporarily mark down nodes that are non-functional.
func NewBalancer ¶
func NewBalancer(getAddresses GetAddressesFunc, retryDelay time.Duration) *Balancer
NewBalancer creates a Balancer. getAddreses is the function it will use to refresh the list of addresses if one of the nodes has been marked down. The list of addresses is shuffled. retryDelay specifies the minimum time a node will be marked down before it will be cleared for a retry.
func (*Balancer) Get ¶
Get returns a single address that was not recently marked down. If it finds an address that was down for longer than retryDelay, it refreshes the list of addresses and returns the next available node. If all addresses are marked down, it waits and retries. If a refresh fails, it returns an error.
type BalancerMap ¶
type BalancerMap struct { Toposerv SubsetTopoServ Cell string PortName string // contains filtered or unexported fields }
BalancerMap builds and maintains a map from cell.keyspace.dbtype.shard to Balancers.
func NewBalancerMap ¶
func NewBalancerMap(serv SubsetTopoServ, cell, namedPort string) *BalancerMap
NewBalancerMap builds a new BalancerMap. Each BalancerMap is dedicated to a cell. serv is the TopoServ used to fetch the list of tablets when needed. The Balancers will be built using the namedPort from each tablet info.
func (*BalancerMap) Balancer ¶
func (blm *BalancerMap) Balancer(keyspace, shard string, tabletType topo.TabletType, retryDelay time.Duration) *Balancer
Balancer creates a Balancer if one doesn't exist for a cell.keyspace.dbtype.shard. If one was previously created, then that is returned. The retryDelay is used only when a Balancer is created.
type GetAddressesFunc ¶
type ScatterConn ¶
type ScatterConn struct { Id int64 // contains filtered or unexported fields }
ScatterConn is used for executing queries across multiple ShardConn connections.
func NewScatterConn ¶
func NewScatterConn(blm *BalancerMap, tabletProtocol string, tabletType topo.TabletType, retryDelay time.Duration, retryCount int) *ScatterConn
NewScatterConn creates a new ScatterConn. All input parameters are passed through for creating the appropriate ShardConn.
func (*ScatterConn) Begin ¶
func (stc *ScatterConn) Begin() error
Begin begins a transaction. The retry rules are the same.
func (*ScatterConn) Close ¶
func (stc *ScatterConn) Close() error
Close closes the underlying ShardConn connections.
func (*ScatterConn) Commit ¶
func (stc *ScatterConn) Commit() (err error)
Commit commits the current transaction. There are no retries on this operation.
func (*ScatterConn) Execute ¶
func (stc *ScatterConn) Execute(query string, bindVars map[string]interface{}, keyspace string, shards []string) (*mproto.QueryResult, error)
Execute executes a non-streaming query on the specified shards.
func (*ScatterConn) ExecuteBatch ¶
func (stc *ScatterConn) ExecuteBatch(queries []proto.BoundQuery, keyspace string, shards []string) (qrs *tproto.QueryResultList, err error)
Execute executes a non-streaming query on the specified shards.
func (*ScatterConn) Rollback ¶
func (stc *ScatterConn) Rollback() (err error)
Rollback rolls back the current transaction. There are no retries on this operation.
func (*ScatterConn) StreamExecute ¶
func (stc *ScatterConn) StreamExecute(query string, bindVars map[string]interface{}, keyspace string, shards []string, sendReply func(reply interface{}) error) error
StreamExecute executes a streaming query on vttablet. The retry rules are the same.
func (*ScatterConn) TransactionId ¶
func (stc *ScatterConn) TransactionId() int64
type ShardConn ¶
type ShardConn struct {
// contains filtered or unexported fields
}
ShardConn represents a load balanced connection to a group of vttablets that belong to the same shard. ShardConn should not be concurrently used across goroutines.
func NewShardConn ¶
func NewShardConn(blm *BalancerMap, tabletProtocol, keyspace, shard string, tabletType topo.TabletType, retryDelay time.Duration, retryCount int) *ShardConn
NewShardConn creates a new ShardConn. It creates or reuses a Balancer from the supplied BalancerMap. retryDelay is as specified by Balancer. retryCount is the max number of retries before a ShardConn returns an error on an operation.
func (*ShardConn) Commit ¶
Commit commits the current transaction. There are no retries on this operation.
func (*ShardConn) Execute ¶
func (sdc *ShardConn) Execute(query string, bindVars map[string]interface{}) (qr *mproto.QueryResult, err error)
Execute executes a non-streaming query on vttablet. If there are connection errors, it retries retryCount times before failing. It does not retry if the connection is in the middle of a transaction.
func (*ShardConn) ExecuteBatch ¶
func (sdc *ShardConn) ExecuteBatch(queries []proto.BoundQuery) (qrs *tproto.QueryResultList, err error)
ExecuteBatch executes a group of queries. The retry rules are the same as Execute.
func (*ShardConn) Rollback ¶
Rollback rolls back the current transaction. There are no retries on this operation.
func (*ShardConn) StreamExecute ¶
func (sdc *ShardConn) StreamExecute(query string, bindVars map[string]interface{}) (results <-chan *mproto.QueryResult, errFunc ErrFunc)
StreamExecute executes a streaming query on vttablet. The retry rules are the same as Execute. Calling other functions while streaming is not recommended.
func (*ShardConn) TransactionId ¶
type SubsetTopoServ ¶
type SubsetTopoServ interface {
GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error)
}
SubsetTopoServ is a subset of topo.Server
type TabletBson ¶
type TabletBson struct {
// contains filtered or unexported fields
}
TabletBson implements a bson rpcplus implementation for TabletConn
func (*TabletBson) Begin ¶
func (conn *TabletBson) Begin() error
func (*TabletBson) Close ¶
func (conn *TabletBson) Close() error
func (*TabletBson) Commit ¶
func (conn *TabletBson) Commit() error
func (*TabletBson) Execute ¶
func (conn *TabletBson) Execute(query string, bindVars map[string]interface{}) (*mproto.QueryResult, error)
func (*TabletBson) ExecuteBatch ¶
func (conn *TabletBson) ExecuteBatch(queries []proto.BoundQuery) (*tproto.QueryResultList, error)
func (*TabletBson) Rollback ¶
func (conn *TabletBson) Rollback() error
func (*TabletBson) StreamExecute ¶
func (conn *TabletBson) StreamExecute(query string, bindVars map[string]interface{}) (<-chan *mproto.QueryResult, ErrFunc)
func (*TabletBson) TransactionId ¶
func (conn *TabletBson) TransactionId() int64
type TabletConn ¶
type TabletConn interface { // Execute executes a non-streaming query on vttablet. Execute(query string, bindVars map[string]interface{}) (*mproto.QueryResult, error) // ExecuteBatch executes a group of queries. ExecuteBatch(queries []proto.BoundQuery) (*tproto.QueryResultList, error) // StreamExecute exectutes a streaming query on vttablet. It returns a channel that will stream results. // It also returns an ErrFunc that can be called to check if there were any errors. ErrFunc can be called // immediately after StreamExecute returns to check if there were errors sending the call. It should also // be called after finishing the iteration over the channel to see if there were other errors. StreamExecute(query string, bindVars map[string]interface{}) (<-chan *mproto.QueryResult, ErrFunc) // Transaction support Begin() error Commit() error Rollback() error // TransactionId returns 0 if there is no transaction. TransactionId() int64 // Close must be called for releasing resources. Close() error }
TabletConn defines the interface for a vttablet client. It should not be concurrently used across goroutines.
func DialTablet ¶
func DialTablet(addr, keyspace, shard, username, password string, encrypted bool) (TabletConn, error)
type TabletDialer ¶
type TabletDialer func(addr, keyspace, shard, username, password string, encrypted bool) (TabletConn, error)
TabletDialer represents a function that will return a TabletConn object that can communicate with a tablet.
func GetDialer ¶
func GetDialer(name string) TabletDialer
type VTGate ¶
type VTGate struct {
// contains filtered or unexported fields
}
VTGate is the rpc interface to vtgate. Only one instance can be created.
var RpcVTGate *VTGate
func (*VTGate) CloseSession ¶
func (vtg *VTGate) CloseSession(context *rpcproto.Context, session *proto.Session, noOutput *string) error
CloseSession closes the current session and releases all associated resources for the session.
func (*VTGate) Commit ¶
func (vtg *VTGate) Commit(context *rpcproto.Context, session *proto.Session, noOutput *string) error
Commit commits a transaction.
func (*VTGate) ExecuteBatchShard ¶
func (vtg *VTGate) ExecuteBatchShard(context *rpcproto.Context, batchQuery *proto.BatchQueryShard, reply *tproto.QueryResultList) error
ExecuteBatchShard executes a group of queries on the specified shards.
func (*VTGate) ExecuteShard ¶
func (vtg *VTGate) ExecuteShard(context *rpcproto.Context, query *proto.QueryShard, reply *mproto.QueryResult) error
ExecuteShard executes a non-streaming query on the specified shards.
func (*VTGate) GetSessionId ¶
GetSessionId is the first request sent by the client to begin a session. The returned id should be used for all subsequent communications.
func (*VTGate) Rollback ¶
func (vtg *VTGate) Rollback(context *rpcproto.Context, session *proto.Session, noOutput *string) error
Rollback rolls back a transaction.
func (*VTGate) StreamExecuteShard ¶
func (vtg *VTGate) StreamExecuteShard(context *rpcproto.Context, query *proto.QueryShard, sendReply func(interface{}) error) error
StreamExecuteShard executes a streaming query on the specified shards.