gateway

package
v3.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

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

View Source
const (

	// StatusTemplate is the display part to use to show
	// a TabletCacheStatusList.
	StatusTemplate = `` /* 845-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func NewShardError

func NewShardError(in error, target *querypb.Target, tablet *topodatapb.Tablet, inTransaction bool) error

NewShardError returns a new error with the shard info amended.

func RegisterCreator

func RegisterCreator(name string, gc Creator)

RegisterCreator registers a Creator with given name.

func StreamHealthFromTargetStatsListener

func StreamHealthFromTargetStatsListener(ctx context.Context, l srvtopo.TargetStatsListener, callback func(*querypb.StreamHealthResponse) error) error

StreamHealthFromTargetStatsListener responds to a StreamHealth streaming RPC using a srvtopo.TargetStatsListener implementation.

func WaitForTablets

func WaitForTablets(gw Gateway, tabletTypesToWait []topodatapb.TabletType) error

WaitForTablets is a helper method to wait for the provided tablets, up until the *initialTabletTimeout. It will log what it is doing. Note it has the same name as the Gateway's interface method, as it just calls it.

Types

type Creator

type Creator func(hc discovery.HealthCheck, serv srvtopo.Server, cell string, retryCount int) 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 {
	// TODO(alainjobart) The QueryService part of this interface
	// will be removed soon, in favor of the TargetStats part (that
	// returns a QueryService)
	queryservice.QueryService

	// srvtopo.TargetStats allows this Gateway to resolve a Target
	// into a QueryService. It is used by the srvtopo.Resolver object.
	srvtopo.TargetStats

	// WaitForTablets asks the gateway to wait for the provided
	// tablets types to be available. It the context is canceled
	// before the end, it should return ctx.Err().
	// The error returned will have specific effects:
	// - nil: keep going with startup.
	// - context.DeadlineExceeded: log a warning that we didn't get
	//   all tablets, and keep going with startup.
	// - any other error: log.Fatalf out.
	WaitForTablets(ctx context.Context, tabletTypesToWait []topodatapb.TabletType) error

	// RegisterStats registers exported stats for the gateway
	RegisterStats()

	// CacheStatus returns a list of TabletCacheStatus per shard / tablet type.
	CacheStatus() TabletCacheStatusList
}

A Gateway is the query processing module for each shard, which is used by ScatterConn.

type HybridGateway

type HybridGateway struct {
	queryservice.QueryService
	// contains filtered or unexported fields
}

HybridGateway implements the gateway.Gateway interface by forwarding the queries to the right underlying implementation:

  • it has one gateway that watches for tablets. Usually a DiscoveryGateway. Useful for local tablets, or remote tablets that can be accessed.
  • it has a list of remote vtgate connections to talk to l2 vtgate processes. Useful for remote tablets that are far away, or if the number of local tablets grows too big.

Note the WaitForTablets method for now only waits on the local gateway.

func NewHybridGateway

func NewHybridGateway(gw Gateway, addrs []string, retryCount int) (*HybridGateway, error)

NewHybridGateway returns a new HybridGateway based on the provided parameters. gw can be nil, in which case it is assumed there is no local tablets.

func (*HybridGateway) CacheStatus

func (h *HybridGateway) CacheStatus() TabletCacheStatusList

CacheStatus is part of the Gateway interface. It just concatenates all statuses from all underlying parts.

func (*HybridGateway) Close

func (h *HybridGateway) Close(ctx context.Context) error

Close is part of the queryservice.QueryService interface.

func (*HybridGateway) GetAggregateStats

func (h *HybridGateway) GetAggregateStats(target *querypb.Target) (*querypb.AggregateStats, queryservice.QueryService, error)

GetAggregateStats is part of the srvtopo.TargetStats interface, included in the gateway.Gateway interface.

func (*HybridGateway) GetMasterCell

func (h *HybridGateway) GetMasterCell(keyspace, shard string) (cell string, qs queryservice.QueryService, err error)

GetMasterCell is part of the srvtopo.TargetStats interface, included in the gateway.Gateway interface.

func (*HybridGateway) RegisterStats

func (h *HybridGateway) RegisterStats()

RegisterStats registers the l2vtgate connection counts stats.

func (*HybridGateway) WaitForTablets

func (h *HybridGateway) WaitForTablets(ctx context.Context, tabletTypesToWait []topodatapb.TabletType) error

WaitForTablets is part of the Gateway interface. We just forward to the local Gateway, if any.

type L2VTGateConn

type L2VTGateConn struct {
	queryservice.QueryService
	// contains filtered or unexported fields
}

L2VTGateConn keeps a single connection to a vtgate backend. The underlying vtgate backend must have been started with the '-enable_forwarding' flag.

It will keep a healthcheck connection going to the target, to get the list of available Targets. It remembers them, and exposes a srvtopo.TargetStats interface to query them.

func NewL2VTGateConn

func NewL2VTGateConn(name, addr string, retryCount int) (*L2VTGateConn, error)

NewL2VTGateConn creates a new L2VTGateConn object. It also starts the background go routine to monitor its health.

func (*L2VTGateConn) CacheStatus

func (c *L2VTGateConn) CacheStatus() TabletCacheStatusList

CacheStatus returns a list of TabletCacheStatus per name:keyspace/shard/tablet type.

func (*L2VTGateConn) Close

func (c *L2VTGateConn) Close(ctx context.Context) error

Close is part of the queryservice.QueryService interface.

func (*L2VTGateConn) GetAggregateStats

func (c *L2VTGateConn) GetAggregateStats(target *querypb.Target) (*querypb.AggregateStats, error)

GetAggregateStats is the discovery part of srvtopo.TargetStats interface.

func (*L2VTGateConn) GetMasterCell

func (c *L2VTGateConn) GetMasterCell(keyspace, shard string) (cell string, err error)

GetMasterCell is the discovery part of the srvtopo.TargetStats interface.

type TabletCacheStatus

type TabletCacheStatus struct {
	Keyspace   string
	Shard      string
	TabletType topodatapb.TabletType
	Name       string
	Addr       string

	QueryCount uint64
	QueryError uint64
	QPS        float64
	AvgLatency float64 // in milliseconds
}

TabletCacheStatus contains the status per destination for a gateway.

func (*TabletCacheStatus) FormattedQPS

func (tcs *TabletCacheStatus) FormattedQPS() string

FormattedQPS shows a 2 digit rounded value of QPS. Used in the HTML template above.

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.

Jump to

Keyboard shortcuts

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