Documentation ¶
Overview ¶
Package vtgate provides query routing rpc services for vttablets.
Index ¶
- Constants
- func Init(blm *BalancerMap, retryDelay time.Duration, retryCount int)
- func RegisterDialer(name string, dialer TabletDialer)
- type Balancer
- type BalancerMap
- type ErrFunc
- type GetEndPointsFunc
- type OperationalError
- type ResilientSrvTopoServer
- func (server *ResilientSrvTopoServer) GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error)
- func (server *ResilientSrvTopoServer) GetSrvKeyspace(cell, keyspace string) (*topo.SrvKeyspace, error)
- func (server *ResilientSrvTopoServer) GetSrvKeyspaceNames(cell string) ([]string, error)
- 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 []tproto.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 ServerError
- 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 []tproto.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 SrvTopoServer
- 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 []tproto.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, ...) error
- func (vtg *VTGate) CloseSession(context *rpcproto.Context, session *proto.Session, ...) error
- func (vtg *VTGate) Commit(context *rpcproto.Context, session *proto.Session, ...) 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, ...) error
- func (vtg *VTGate) StreamExecuteShard(context *rpcproto.Context, query *proto.QueryShard, ...) error
Constants ¶
const ( ERR_NORMAL = iota ERR_RETRY ERR_FATAL ERR_TX_POOL_FULL ERR_NOT_IN_TX )
Variables ¶
This section is empty.
Functions ¶
func RegisterDialer ¶
func RegisterDialer(name string, dialer TabletDialer)
RegisterDialer is meant to be used by TabletDialer implementations to self register.
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(getEndPoints GetEndPointsFunc, 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 endpoint 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 SrvTopoServer Cell string // contains filtered or unexported fields }
BalancerMap builds and maintains a map from cell.keyspace.dbtype.shard to Balancers.
func NewBalancerMap ¶
func NewBalancerMap(serv SrvTopoServer, cell 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.
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 GetEndPointsFunc ¶
type OperationalError ¶
type OperationalError string
OperationalError represents an error due to a failure to communicate with vttablet.
func (OperationalError) Error ¶
func (e OperationalError) Error() string
type ResilientSrvTopoServer ¶
type ResilientSrvTopoServer struct {
// contains filtered or unexported fields
}
ResilientSrvTopoServer is an implementation of SrvTopoServer based on another SrvTopoServer that uses a cache for two purposes: - limit the QPS to the underlying SrvTopoServer - return the last known value of the data if there is an error
func NewResilientSrvTopoServer ¶
func NewResilientSrvTopoServer(base SrvTopoServer) *ResilientSrvTopoServer
NewResilientSrvTopoServer creates a new ResilientSrvTopoServer based on the provided SrvTopoServer.
func (*ResilientSrvTopoServer) GetEndPoints ¶
func (server *ResilientSrvTopoServer) GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error)
func (*ResilientSrvTopoServer) GetSrvKeyspace ¶
func (server *ResilientSrvTopoServer) GetSrvKeyspace(cell, keyspace string) (*topo.SrvKeyspace, error)
func (*ResilientSrvTopoServer) GetSrvKeyspaceNames ¶
func (server *ResilientSrvTopoServer) GetSrvKeyspaceNames(cell string) ([]string, error)
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, 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 []tproto.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 ServerError ¶
ServerError represents an error that was returned from a vttablet server.
func (*ServerError) Error ¶
func (e *ServerError) Error() string
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, 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 []tproto.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 SrvTopoServer ¶
type SrvTopoServer interface { GetSrvKeyspaceNames(cell string) ([]string, error) GetSrvKeyspace(cell, keyspace string) (*topo.SrvKeyspace, error) GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error) }
SrvTopoServer is a subset of topo.Server that only contains the serving graph read-only calls used by clients to resolve serving addresses.
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 []tproto.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 []tproto.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(endPoint topo.EndPoint, keyspace, shard string) (TabletConn, error)
type TabletDialer ¶
type TabletDialer func(endPoint topo.EndPoint, keyspace, shard string) (TabletConn, error)
TabletDialer represents a function that will return a TabletConn object that can communicate with a tablet.
func GetDialer ¶
func GetDialer() TabletDialer
GetDialer returns the dialer to use, described by the command line flag
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) Begin ¶
func (vtg *VTGate) Begin(context *rpcproto.Context, session *proto.Session, noOutput *rpc.UnusedResponse) error
Begin begins a transaction. It has to be concluded by a Commit or Rollback.
func (*VTGate) CloseSession ¶
func (vtg *VTGate) CloseSession(context *rpcproto.Context, session *proto.Session, noOutput *rpc.UnusedResponse) 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 *rpc.UnusedResponse) 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 *rpc.UnusedResponse) 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.