Documentation ¶
Overview ¶
Package gateway contains the routing layer of vtgate. A Gateway can take a query targeted to a keyspace/shard/tablet_type and send it off.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewShardError ¶
func NewShardError(in error, keyspace, shard string, tabletType topodatapb.TabletType, tablet *topodatapb.Tablet, inTransaction bool) error
NewShardError returns a ShardError which preserves the original error code if possible, adds the connection context and adds a bit to determine whether the keyspace/shard needs to be re-resolved for a potential sharding event (namely, if we were in a transaction).
func RegisterCreator ¶
RegisterCreator registers a Creator with given name.
Types ¶
type Creator ¶
type Creator func(hc discovery.HealthCheck, topoServer topo.Server, serv topo.SrvTopoServer, cell string, retryCount int, tabletTypesToWait []topodatapb.TabletType) Gateway
Creator is the factory method which can create the actual gateway object.
func GetCreator ¶
func GetCreator() Creator
GetCreator returns the Creator specified by the gateway_implementation flag.
type Gateway ¶
type Gateway interface { // Execute executes the non-streaming query for the specified keyspace, shard, and tablet type. Execute(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, query string, bindVars map[string]interface{}, transactionID int64) (*sqltypes.Result, error) // ExecuteBatch executes a group of queries for the specified keyspace, shard, and tablet type. ExecuteBatch(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, queries []querytypes.BoundQuery, asTransaction bool, transactionID int64) ([]sqltypes.Result, error) // StreamExecute executes a streaming query for the specified keyspace, shard, and tablet type. StreamExecute(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, query string, bindVars map[string]interface{}) (sqltypes.ResultStream, error) // Begin starts a transaction for the specified keyspace, shard, and tablet type. // It returns the transaction ID. Begin(ctx context.Context, keyspace string, shard string, tabletType topodatapb.TabletType) (int64, error) // Commit commits the current transaction for the specified keyspace, shard, and tablet type. Commit(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, transactionID int64) error // Rollback rolls back the current transaction for the specified keyspace, shard, and tablet type. Rollback(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, transactionID int64) error // BeginExecute executes a begin and the non-streaming query // for the specified keyspace, shard, and tablet type. BeginExecute(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, query string, bindVars map[string]interface{}) (*sqltypes.Result, int64, error) // BeginExecuteBatch executes a begin and a group of queries // for the specified keyspace, shard, and tablet type. BeginExecuteBatch(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, queries []querytypes.BoundQuery, asTransaction bool) ([]sqltypes.Result, int64, error) // SplitQuery splits a query into sub-queries for the specified keyspace, shard, and tablet type. SplitQuery(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, sql string, bindVariables map[string]interface{}, splitColumn string, splitCount int64) ([]querytypes.QuerySplit, error) // SplitQuery splits a query into sub-queries for the specified keyspace, shard, and tablet type. // TODO(erez): Rename to SplitQuery after migration to SplitQuery V2. SplitQueryV2( ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, sql string, bindVariables map[string]interface{}, splitColumns []string, splitCount int64, numRowsPerQueryPart int64, algorithm querypb.SplitQueryRequest_Algorithm) ([]querytypes.QuerySplit, error) // Close shuts down underlying connections. Close(ctx context.Context) error // CacheStatus returns a list of TabletCacheStatus per tablet. CacheStatus() TabletCacheStatusList }
A Gateway is the query processing module for each shard, which is used by ScatterConn.
type ShardError ¶
type ShardError struct { // ShardIdentifier is the keyspace+shard. ShardIdentifier string // InTransaction indicates if it is inside a transaction. InTransaction bool // Err preserves the original error, so that we don't need to parse the error string. Err error // ErrorCode is the error code to use for all the tablet errors in aggregate ErrorCode vtrpcpb.ErrorCode }
ShardError is the error about a specific shard. It implements vterrors.VtError.
func (*ShardError) VtErrorCode ¶
func (e *ShardError) VtErrorCode() vtrpcpb.ErrorCode
VtErrorCode returns the underlying Vitess error code. This is part of vterrors.VtError interface.
type TabletCacheStatus ¶
type TabletCacheStatus struct { Keyspace string Shard string TabletType topodatapb.TabletType Name string Addr string QueryCount uint64 QueryError uint64 QPS uint64 AvgLatency float64 // in milliseconds }
TabletCacheStatus contains the status per tablet for a gateway.
type TabletCacheStatusList ¶
type TabletCacheStatusList []*TabletCacheStatus
TabletCacheStatusList is a slice of TabletCacheStatus.
func (TabletCacheStatusList) Len ¶
func (gtcsl TabletCacheStatusList) Len() int
Len is part of sort.Interface.
func (TabletCacheStatusList) Less ¶
func (gtcsl TabletCacheStatusList) Less(i, j int) bool
Less is part of sort.Interface.
func (TabletCacheStatusList) Swap ¶
func (gtcsl TabletCacheStatusList) Swap(i, j int)
Swap is part of sort.Interface.
type TabletStatusAggregator ¶
type TabletStatusAggregator struct { Keyspace string Shard string TabletType topodatapb.TabletType Name string // the alternative name of a tablet Addr string // the host:port of a tablet QueryCount uint64 QueryError uint64 // contains filtered or unexported fields }
TabletStatusAggregator tracks tablet status for a gateway.
func NewTabletStatusAggregator ¶
func NewTabletStatusAggregator(keyspace, shard string, tabletType topodatapb.TabletType, name string) *TabletStatusAggregator
NewTabletStatusAggregator creates a TabletStatusAggregator.
func (*TabletStatusAggregator) GetCacheStatus ¶
func (tsa *TabletStatusAggregator) GetCacheStatus() *TabletCacheStatus
GetCacheStatus returns a TabletCacheStatus representing the current gateway status.
func (*TabletStatusAggregator) UpdateQueryInfo ¶
func (tsa *TabletStatusAggregator) UpdateQueryInfo(addr string, tabletType topodatapb.TabletType, elapsed time.Duration, hasError bool)
UpdateQueryInfo updates the aggregator with the given information about a query.