vtgate

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: Apache-2.0 Imports: 74 Imported by: 5

Documentation

Overview

Package vtgate provides query routing rpc services for vttablets.

Index

Constants

View Source
const (
	// ExecutorTemplate is the HTML template to display ExecutorStats.
	ExecutorTemplate = `` /* 2779-byte string literal not displayed */

)
View Source
const (
	// GatewayImplementationDiscovery defines the string value used as the implementation key for DiscoveryGateway
	GatewayImplementationDiscovery = "discoverygateway"
)
View Source
const MaxSkew = int64(2)

MaxSkew is the threshold for a skew to be detected. Since MySQL timestamps are in seconds we account for two round-offs: one for the actual event and another while accounting for the clock skew

View Source
const (

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

)
View Source
const (
	// VSchemaTemplate is the HTML template to display VSchemaStats.
	VSchemaTemplate = `` /* 749-byte string literal not displayed */

)

Variables

View Source
var (
	// GatewayImplementation allows you to choose which gateway to use for vtgate routing. Defaults to tabletgateway, other option is discoverygateway
	GatewayImplementation = flag.String("gateway_implementation", "tabletgateway", "Allowed values: discoverygateway (deprecated), tabletgateway (default)")

	// RetryCount is the number of times a query will be retried on error
	// Make this unexported after DiscoveryGateway is deprecated
	RetryCount = flag.Int("retry-count", 2, "retry count")
)
View Source
var (
	// QueryLogHandler is the debug UI path for exposing query logs
	QueryLogHandler = "/debug/querylog"

	// QueryLogzHandler is the debug UI path for exposing query logs
	QueryLogzHandler = "/debug/querylogz"

	// QueryzHandler is the debug UI path for exposing query plan stats
	QueryzHandler = "/debug/queryz"

	// QueryLogger enables streaming logging of queries
	QueryLogger = streamlog.New("VTGate", 10)
)
View Source
var (

	// HealthCheckRetryDelay is the time to wait before retrying healthcheck
	HealthCheckRetryDelay = flag.Duration("healthcheck_retry_delay", 2*time.Millisecond, "health check retry delay")
	// HealthCheckTimeout is the timeout on the RPC call to tablets
	HealthCheckTimeout = flag.Duration("healthcheck_timeout", time.Minute, "the health check timeout period")
)
View Source
var (

	// CellsToWatch is the list of cells the healthcheck operates over. If it is empty, only the local cell is watched
	CellsToWatch = flag.String("cells_to_watch", "", "comma-separated list of cells for watching tablets")
)
View Source
var RegisterVTGates []RegisterVTGate

RegisterVTGates stores register funcs for VTGate server.

Functions

func CreateFakeServers

func CreateFakeServers(t *testing.T) (*tabletconntest.FakeQueryService, *topo.Server, string)

CreateFakeServers returns the servers to use for these tests

func NewShardError

func NewShardError(in error, target *querypb.Target) error

NewShardError returns a new error with the shard info amended.

func RegisterGatewayCreator

func RegisterGatewayCreator(name string, gc Creator)

RegisterGatewayCreator registers a Creator with given name.

func RegisterPluginInitializer

func RegisterPluginInitializer(initializer func())

RegisterPluginInitializer lets plugins register themselves to be init'ed at servenv.OnRun-time

func TestSuite

func TestSuite(t *testing.T, name string, g Gateway, f *tabletconntest.FakeQueryService)

TestSuite executes a set of tests on the provided gateway. The provided gateway needs to be configured with one established connection for tabletconntest.TestTarget.{Keyspace, Shard, TabletType} to the provided tabletconntest.FakeQueryService.

func UsingLegacyGateway

func UsingLegacyGateway() bool

UsingLegacyGateway returns true when legacy

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(ctx context.Context, hc discovery.LegacyHealthCheck, serv srvtopo.Server, cell string, retryCount int) Gateway

Creator is the factory method which can create the actual gateway object.

func GatewayCreator

func GatewayCreator() Creator

GatewayCreator returns the Creator specified by the gateway_implementation flag.

type DiscoveryGateway

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

DiscoveryGateway is not the default Gateway implementation anymore. This implementation uses the legacy healthcheck module.

func NewDiscoveryGateway

func NewDiscoveryGateway(ctx context.Context, hc discovery.LegacyHealthCheck, serv srvtopo.Server, cell string, retryCount int) *DiscoveryGateway

NewDiscoveryGateway creates a new DiscoveryGateway using the provided healthcheck and toposerver. cell is the cell where the gateway is located a.k.a localCell. This gateway can route to MASTER in any cell provided by the cells_to_watch command line argument. Other tablet type requests (REPLICA/RDONLY) are only routed to tablets in the same cell.

func (*DiscoveryGateway) CacheStatus

func (dg *DiscoveryGateway) CacheStatus() TabletCacheStatusList

CacheStatus returns a list of TabletCacheStatus per keyspace/shard/tablet_type.

func (*DiscoveryGateway) Close

func (dg *DiscoveryGateway) Close(ctx context.Context) error

Close shuts down underlying connections. This function hides the inner implementation.

func (*DiscoveryGateway) QueryServiceByAlias

QueryServiceByAlias satisfies the Gateway interface

func (*DiscoveryGateway) RegisterStats

func (dg *DiscoveryGateway) RegisterStats()

RegisterStats registers the stats to export the lag since the last refresh and the checksum of the topology

func (*DiscoveryGateway) StatsUpdate

func (dg *DiscoveryGateway) StatsUpdate(ts *discovery.LegacyTabletStats)

StatsUpdate forwards LegacyHealthCheck updates to LegacyTabletStatsCache and MasterBuffer. It is part of the discovery.LegacyHealthCheckStatsListener interface.

func (*DiscoveryGateway) TabletsCacheStatus

func (dg *DiscoveryGateway) TabletsCacheStatus() discovery.TabletsCacheStatusList

TabletsCacheStatus is not implemented for this struct

func (*DiscoveryGateway) WaitForTablets

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

WaitForTablets is part of the gateway.Gateway interface.

type Executor

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

Executor is the engine that executes queries by utilizing the abilities of the underlying vttablets.

func NewExecutor

func NewExecutor(
	ctx context.Context,
	serv srvtopo.Server,
	cell string,
	resolver *Resolver,
	normalize, warnOnShardedOnly bool,
	streamSize int,
	cacheCfg *cache.Config,
	schemaTracker SchemaInfo,
) *Executor

NewExecutor creates a new Executor.

func (*Executor) CloseSession

func (e *Executor) CloseSession(ctx context.Context, safeSession *SafeSession) error

CloseSession releases the current connection, which rollbacks open transactions and closes reserved connections. It is called then the MySQL servers closes the connection to its client.

func (*Executor) Commit added in v0.8.0

func (e *Executor) Commit(ctx context.Context, safeSession *SafeSession) error

Commit commits the existing transactions

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, method string, safeSession *SafeSession, sql string, bindVars map[string]*querypb.BindVariable) (result *sqltypes.Result, err error)

Execute executes a non-streaming query.

func (*Executor) ExecuteLock added in v0.8.0

func (e *Executor) ExecuteLock(ctx context.Context, rs *srvtopo.ResolvedShard, query *querypb.BoundQuery, session *SafeSession) (*sqltypes.Result, error)

ExecuteLock implements the IExecutor interface

func (*Executor) ExecuteMessageStream added in v0.11.0

func (e *Executor) ExecuteMessageStream(ctx context.Context, rss []*srvtopo.ResolvedShard, tableName string, callback func(reply *sqltypes.Result) error) error

ExecuteMessageStream implements the IExecutor interface

func (*Executor) ExecuteMultiShard

func (e *Executor) ExecuteMultiShard(ctx context.Context, rss []*srvtopo.ResolvedShard, queries []*querypb.BoundQuery, session *SafeSession, autocommit bool, ignoreMaxMemoryRows bool) (qr *sqltypes.Result, errs []error)

ExecuteMultiShard implements the IExecutor interface

func (*Executor) ExecuteVStream added in v0.11.0

func (e *Executor) ExecuteVStream(ctx context.Context, rss []*srvtopo.ResolvedShard, filter *binlogdatapb.Filter, gtid string, callback func(evs []*binlogdatapb.VEvent) error) error

ExecuteVStream implements the IExecutor interface

func (*Executor) MessageStream

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

MessageStream is part of the vtgate service API. This is a V2 level API that's sent to the Resolver.

func (*Executor) ParseDestinationTarget

func (e *Executor) ParseDestinationTarget(targetString string) (string, topodatapb.TabletType, key.Destination, error)

ParseDestinationTarget parses destination target string and sets default keyspace if possible.

func (*Executor) Plans

func (e *Executor) Plans() cache.Cache

Plans returns the LRU plan cache

func (*Executor) Prepare

func (e *Executor) Prepare(ctx context.Context, method string, safeSession *SafeSession, sql string, bindVars map[string]*querypb.BindVariable) (fld []*querypb.Field, err error)

Prepare executes a prepare statements.

func (*Executor) SaveVSchema

func (e *Executor) SaveVSchema(vschema *vindexes.VSchema, stats *VSchemaStats)

SaveVSchema updates the vschema and stats

func (*Executor) ServeHTTP

func (e *Executor) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP shows the current plans in the query cache.

func (*Executor) StreamExecute

func (e *Executor) StreamExecute(ctx context.Context, method string, safeSession *SafeSession, sql string, bindVars map[string]*querypb.BindVariable, target *querypb.Target, callback func(*sqltypes.Result) error) (err error)

StreamExecute executes a streaming query.

func (*Executor) StreamExecuteMulti

func (e *Executor) StreamExecuteMulti(ctx context.Context, query string, rss []*srvtopo.ResolvedShard, vars []map[string]*querypb.BindVariable, options *querypb.ExecuteOptions, callback func(reply *sqltypes.Result) error) []error

StreamExecuteMulti implements the IExecutor interface

func (*Executor) VSchema

func (e *Executor) VSchema() *vindexes.VSchema

VSchema returns the VSchema.

func (*Executor) VSchemaStats

func (e *Executor) VSchemaStats() *VSchemaStats

VSchemaStats returns the loaded vschema stats.

func (*Executor) WriteScatterStats

func (e *Executor) WriteScatterStats(w http.ResponseWriter)

WriteScatterStats will write an html report to the provided response writer

type Gateway

type Gateway interface {
	// the query service that this Gateway wraps around
	queryservice.QueryService

	// 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

	// TabletsCacheStatus returns a displayable version of the health check cache.
	TabletsCacheStatus() discovery.TabletsCacheStatusList

	// TabletByAlias returns a QueryService
	QueryServiceByAlias(alias *topodatapb.TabletAlias, target *querypb.Target) (queryservice.QueryService, error)
}

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

type LogStats

type LogStats struct {
	Ctx           context.Context
	Method        string
	Keyspace      string
	TabletType    string
	Table         string
	StmtType      string
	SQL           string
	BindVariables map[string]*querypb.BindVariable
	StartTime     time.Time
	EndTime       time.Time
	ShardQueries  uint64
	RowsAffected  uint64
	RowsReturned  uint64
	PlanTime      time.Duration
	ExecuteTime   time.Duration
	CommitTime    time.Duration
	Error         error
}

LogStats records the stats for a single vtgate query

func NewLogStats

func NewLogStats(ctx context.Context, methodName, sql string, bindVars map[string]*querypb.BindVariable) *LogStats

NewLogStats constructs a new LogStats with supplied Method and ctx field values, and the StartTime field set to the present time.

func (*LogStats) Context

func (stats *LogStats) Context() context.Context

Context returns the context used by LogStats.

func (*LogStats) ContextHTML

func (stats *LogStats) ContextHTML() template.HTML

ContextHTML returns the HTML version of the context that was used, or "". This is a method on LogStats instead of a field so that it doesn't need to be passed by value everywhere.

func (*LogStats) EffectiveCaller

func (stats *LogStats) EffectiveCaller() string

EffectiveCaller returns the effective caller stored in LogStats.Ctx

func (*LogStats) ErrorStr

func (stats *LogStats) ErrorStr() string

ErrorStr returns the error string or ""

func (*LogStats) EventTime

func (stats *LogStats) EventTime() time.Time

EventTime returns the time the event was created.

func (*LogStats) ImmediateCaller

func (stats *LogStats) ImmediateCaller() string

ImmediateCaller returns the immediate caller stored in LogStats.Ctx

func (*LogStats) Logf

func (stats *LogStats) Logf(w io.Writer, params url.Values) error

Logf formats the log record to the given writer, either as tab-separated list of logged fields or as JSON.

func (*LogStats) RemoteAddrUsername

func (stats *LogStats) RemoteAddrUsername() (string, string)

RemoteAddrUsername returns some parts of CallInfo if set

func (*LogStats) Send

func (stats *LogStats) Send()

Send finalizes a record and sends it

func (*LogStats) TotalTime

func (stats *LogStats) TotalTime() time.Duration

TotalTime returns how long this query has been running

type RegisterVTGate

type RegisterVTGate func(vtgateservice.VTGateService)

RegisterVTGate defines the type of registration mechanism.

type Resolver

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

Resolver is the layer to resolve KeyspaceIds and KeyRanges to shards. It will try to re-resolve shards if ScatterConn returns retryable error, which may imply horizontal or vertical resharding happened. It is implemented using a srvtopo.Resolver.

func NewResolver

func NewResolver(resolver *srvtopo.Resolver, serv srvtopo.Server, cell string, sc *ScatterConn) *Resolver

NewResolver creates a new Resolver.

func (*Resolver) Execute

func (res *Resolver) Execute(
	ctx context.Context,
	sql string,
	bindVars map[string]*querypb.BindVariable,
	keyspace string,
	tabletType topodatapb.TabletType,
	destination key.Destination,
	session *SafeSession,
	options *querypb.ExecuteOptions,
	logStats *LogStats,
	canAutocommit bool,
	ignoreMaxMemoryRows bool,
) (*sqltypes.Result, error)

Execute executes a non-streaming query based on provided destination. It retries query if new keyspace/shards are re-resolved after a retryable error.

func (*Resolver) GetGatewayCacheStatus

func (res *Resolver) GetGatewayCacheStatus() TabletCacheStatusList

GetGatewayCacheStatus returns a displayable version of the Gateway cache.

func (*Resolver) MessageStream

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

MessageStream streams messages.

func (*Resolver) StreamExecute

func (res *Resolver) StreamExecute(
	ctx context.Context,
	sql string,
	bindVars map[string]*querypb.BindVariable,
	keyspace string,
	tabletType topodatapb.TabletType,
	destination key.Destination,
	options *querypb.ExecuteOptions,
	callback func(*sqltypes.Result) error,
) error

StreamExecute executes a streaming query on shards resolved by given func. This function currently temporarily enforces the restriction of executing on one shard since it cannot merge-sort the results to guarantee ordering of response which is needed for checkpointing. Note we guarantee the callback will not be called concurrently by multiple go routines.

type SafeSession

type SafeSession struct {
	*vtgatepb.Session
	// contains filtered or unexported fields
}

SafeSession is a mutex-protected version of the Session. It is thread-safe if each thread only accesses one shard. (the use pattern is 'Find', if not found, then 'AppendOrUpdate', for a single shard)

func NewAutocommitSession

func NewAutocommitSession(sessn *vtgatepb.Session) *SafeSession

NewAutocommitSession returns a SafeSession based on the original session, but with autocommit enabled.

func NewSafeSession

func NewSafeSession(sessn *vtgatepb.Session) *SafeSession

NewSafeSession returns a new SafeSession based on the Session

func (*SafeSession) AppendOrUpdate

func (session *SafeSession) AppendOrUpdate(shardSession *vtgatepb.Session_ShardSession, txMode vtgatepb.TransactionMode) error

AppendOrUpdate adds a new ShardSession, or updates an existing one if one already exists for the given shard session

func (*SafeSession) AutocommitApproval

func (session *SafeSession) AutocommitApproval() bool

AutocommitApproval returns true if we can perform a single round-trip autocommit. If so, the caller is responsible for committing their transaction.

func (*SafeSession) ClearWarnings

func (session *SafeSession) ClearWarnings()

ClearWarnings removes all the warnings from the session

func (*SafeSession) Find

func (session *SafeSession) Find(keyspace, shard string, tabletType topodatapb.TabletType) (transactionID int64, reservedID int64, alias *topodatapb.TabletAlias)

Find returns the transactionId and tabletAlias, if any, for a session

func (*SafeSession) GetDDLStrategy added in v0.9.0

func (session *SafeSession) GetDDLStrategy() string

GetDDLStrategy returns the DDLStrategy value.

func (*SafeSession) GetOrCreateOptions added in v0.8.0

func (session *SafeSession) GetOrCreateOptions() *querypb.ExecuteOptions

GetOrCreateOptions will return the current options struct, or create one and return it if no-one exists

func (*SafeSession) GetSessionEnableSystemSettings added in v0.10.0

func (session *SafeSession) GetSessionEnableSystemSettings() bool

GetSessionEnableSystemSettings returns the SessionEnableSystemSettings value.

func (*SafeSession) GetSessionUUID added in v0.9.0

func (session *SafeSession) GetSessionUUID() string

GetSessionUUID returns the SessionUUID value.

func (*SafeSession) InLockSession added in v0.8.0

func (session *SafeSession) InLockSession() bool

InLockSession returns whether locking is used on this session.

func (*SafeSession) InReservedConn

func (session *SafeSession) InReservedConn() bool

InReservedConn returns true if the session needs to execute on a dedicated connection

func (*SafeSession) InTransaction

func (session *SafeSession) InTransaction() bool

InTransaction returns true if we are in a transaction

func (*SafeSession) MustRollback

func (session *SafeSession) MustRollback() bool

MustRollback returns true if the transaction must be rolled back.

func (*SafeSession) RecordWarning

func (session *SafeSession) RecordWarning(warning *querypb.QueryWarning)

RecordWarning stores the given warning in the session

func (*SafeSession) Reset

func (session *SafeSession) Reset()

Reset clears the session

func (*SafeSession) ResetAll added in v0.8.0

func (session *SafeSession) ResetAll()

ResetAll resets the shard sessions and lock session.

func (*SafeSession) ResetLock added in v0.8.0

func (session *SafeSession) ResetLock()

ResetLock resets the lock session

func (*SafeSession) ResetShard added in v0.8.0

func (session *SafeSession) ResetShard(tabletAlias *topodatapb.TabletAlias) error

ResetShard reset the shard session for the provided tablet alias.

func (*SafeSession) ResetTx

func (session *SafeSession) ResetTx()

ResetTx clears the session

func (*SafeSession) SetAutocommittable

func (session *SafeSession) SetAutocommittable(flag bool)

SetAutocommittable sets the state to autocommitable if true. Otherwise, it's notAutocommitable.

func (*SafeSession) SetCommitOrder

func (session *SafeSession) SetCommitOrder(co vtgatepb.CommitOrder)

SetCommitOrder sets the commit order.

func (*SafeSession) SetDDLStrategy added in v0.9.0

func (session *SafeSession) SetDDLStrategy(strategy string)

SetDDLStrategy set the DDLStrategy setting.

func (*SafeSession) SetLockSession added in v0.8.0

func (session *SafeSession) SetLockSession(lockSession *vtgatepb.Session_ShardSession)

SetLockSession sets the lock session.

func (*SafeSession) SetOptions

func (session *SafeSession) SetOptions(options *querypb.ExecuteOptions)

SetOptions sets the options

func (*SafeSession) SetPreQueries

func (session *SafeSession) SetPreQueries() []string

SetPreQueries returns the prequeries that need to be run when reserving a connection

func (*SafeSession) SetReadAfterWriteGTID added in v0.9.0

func (session *SafeSession) SetReadAfterWriteGTID(vtgtid string)

SetReadAfterWriteGTID set the ReadAfterWriteGtid setting.

func (*SafeSession) SetReadAfterWriteTimeout added in v0.9.0

func (session *SafeSession) SetReadAfterWriteTimeout(timeout float64)

SetReadAfterWriteTimeout set the ReadAfterWriteTimeout setting.

func (*SafeSession) SetReservedConn

func (session *SafeSession) SetReservedConn(reservedConn bool)

SetReservedConn set the InReservedConn setting.

func (*SafeSession) SetRollback

func (session *SafeSession) SetRollback()

SetRollback sets the flag indicating that the transaction must be rolled back. The call is a no-op if the session is not in a transaction.

func (*SafeSession) SetSessionEnableSystemSettings added in v0.10.0

func (session *SafeSession) SetSessionEnableSystemSettings(allow bool)

SetSessionEnableSystemSettings set the SessionEnableSystemSettings setting.

func (*SafeSession) SetSessionTrackGtids added in v0.9.0

func (session *SafeSession) SetSessionTrackGtids(enable bool)

SetSessionTrackGtids set the SessionTrackGtids setting.

func (*SafeSession) SetSystemVariable

func (session *SafeSession) SetSystemVariable(name string, expr string)

SetSystemVariable sets the system variable in th session.

func (*SafeSession) SetTargetString

func (session *SafeSession) SetTargetString(target string)

SetTargetString sets the target string in the session.

func (*SafeSession) SetUserDefinedVariable

func (session *SafeSession) SetUserDefinedVariable(key string, value *querypb.BindVariable)

SetUserDefinedVariable sets the user defined variable in the session.

func (*SafeSession) StoreSavepoint

func (session *SafeSession) StoreSavepoint(sql string)

StoreSavepoint stores the savepoint and release savepoint queries in the session

func (*SafeSession) TriggerLockHeartBeat added in v0.8.0

func (session *SafeSession) TriggerLockHeartBeat() bool

TriggerLockHeartBeat returns if it time to trigger next lock heartbeat

func (*SafeSession) UpdateLockHeartbeat added in v0.8.0

func (session *SafeSession) UpdateLockHeartbeat()

UpdateLockHeartbeat updates the LastLockHeartbeat time

type ScatterConn

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

ScatterConn is used for executing queries across multiple shard level connections.

func NewLegacyScatterConn

func NewLegacyScatterConn(statsName string, txConn *TxConn, gw Gateway, hc discovery.LegacyHealthCheck) *ScatterConn

NewLegacyScatterConn creates a new ScatterConn.

func NewScatterConn

func NewScatterConn(statsName string, txConn *TxConn, gw *TabletGateway) *ScatterConn

NewScatterConn creates a new ScatterConn.

func (*ScatterConn) Close

func (stc *ScatterConn) Close() error

Close closes the underlying Gateway.

func (*ScatterConn) ExecuteLock added in v0.8.0

func (stc *ScatterConn) ExecuteLock(
	ctx context.Context,
	rs *srvtopo.ResolvedShard,
	query *querypb.BoundQuery,
	session *SafeSession,
) (*sqltypes.Result, error)

ExecuteLock performs the requested 'action' on the specified ResolvedShard. If the lock session already has a reserved connection, it reuses it. Otherwise open a new reserved connection. The action function must match the shardActionTransactionFunc signature.

It returns an error recorder in which each shard error is recorded positionally, i.e. if rss[2] had an error, then the error recorder will store that error in the second position.

func (*ScatterConn) ExecuteMultiShard

func (stc *ScatterConn) ExecuteMultiShard(
	ctx context.Context,
	rss []*srvtopo.ResolvedShard,
	queries []*querypb.BoundQuery,
	session *SafeSession,
	autocommit bool,
	ignoreMaxMemoryRows bool,
) (qr *sqltypes.Result, errs []error)

ExecuteMultiShard is like Execute, but each shard gets its own Sql Queries and BindVariables.

It always returns a non-nil query result and an array of shard errors which may be nil so that callers can optionally process a partially-successful operation.

func (*ScatterConn) GetGatewayCacheStatus

func (stc *ScatterConn) GetGatewayCacheStatus() TabletCacheStatusList

GetGatewayCacheStatus returns a displayable version of the Gateway cache.

func (*ScatterConn) GetHealthCheckCacheStatus

func (stc *ScatterConn) GetHealthCheckCacheStatus() discovery.TabletsCacheStatusList

GetHealthCheckCacheStatus returns a displayable version of the HealthCheck cache.

func (*ScatterConn) GetLegacyHealthCheckCacheStatus

func (stc *ScatterConn) GetLegacyHealthCheckCacheStatus() discovery.LegacyTabletsCacheStatusList

GetLegacyHealthCheckCacheStatus returns a displayable version of the HealthCheck cache.

func (*ScatterConn) MessageStream

func (stc *ScatterConn) MessageStream(ctx context.Context, rss []*srvtopo.ResolvedShard, name string, callback func(*sqltypes.Result) error) error

MessageStream streams messages from the specified shards. Note we guarantee the callback will not be called concurrently by multiple go routines, through processOneStreamingResult.

func (*ScatterConn) StreamExecute

func (stc *ScatterConn) StreamExecute(
	ctx context.Context,
	query string,
	bindVars map[string]*querypb.BindVariable,
	rss []*srvtopo.ResolvedShard,
	options *querypb.ExecuteOptions,
	callback func(reply *sqltypes.Result) error,
) error

StreamExecute executes a streaming query on vttablet. The retry rules are the same. Note we guarantee the callback will not be called concurrently by multiple go routines, through processOneStreamingResult.

func (*ScatterConn) StreamExecuteMulti

func (stc *ScatterConn) StreamExecuteMulti(
	ctx context.Context,
	query string,
	rss []*srvtopo.ResolvedShard,
	bindVars []map[string]*querypb.BindVariable,
	options *querypb.ExecuteOptions,
	callback func(reply *sqltypes.Result) error,
) []error

StreamExecuteMulti is like StreamExecute, but each shard gets its own bindVars. If len(shards) is not equal to len(bindVars), the function panics. Note we guarantee the callback will not be called concurrently by multiple go routines, through processOneStreamingResult.

type SchemaInfo added in v0.11.0

type SchemaInfo interface {
	Tables(ks string) map[string][]vindexes.Column
}

SchemaInfo is an interface to schema tracker.

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 TabletGateway

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

TabletGateway implements the Gateway interface. This implementation uses the new healthcheck module.

func NewTabletGateway

func NewTabletGateway(ctx context.Context, hc discovery.HealthCheck, serv srvtopo.Server, localCell string) *TabletGateway

NewTabletGateway creates and returns a new TabletGateway NewTabletGateway is the default Gateway implementation

func (*TabletGateway) CacheStatus

func (gw *TabletGateway) CacheStatus() TabletCacheStatusList

CacheStatus returns a list of TabletCacheStatus per keyspace/shard/tablet_type.

func (*TabletGateway) Close

func (gw *TabletGateway) Close(_ context.Context) error

Close shuts down underlying connections. This function hides the inner implementation.

func (*TabletGateway) QueryServiceByAlias

func (gw *TabletGateway) QueryServiceByAlias(alias *topodatapb.TabletAlias, target *querypb.Target) (queryservice.QueryService, error)

QueryServiceByAlias satisfies the Gateway interface

func (*TabletGateway) RegisterStats

func (gw *TabletGateway) RegisterStats()

RegisterStats registers the stats to export the lag since the last refresh and the checksum of the topology

func (*TabletGateway) TabletsCacheStatus

func (gw *TabletGateway) TabletsCacheStatus() discovery.TabletsCacheStatusList

TabletsCacheStatus returns a displayable version of the health check cache.

func (*TabletGateway) WaitForTablets

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

WaitForTablets is part of the Gateway 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.

type TxConn

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

TxConn is used for executing transactional requests.

func NewTxConn

func NewTxConn(gw Gateway, txMode vtgatepb.TransactionMode) *TxConn

NewTxConn builds a new TxConn.

func (*TxConn) Begin

func (txc *TxConn) Begin(ctx context.Context, session *SafeSession) error

Begin begins a new transaction. If one is already in progress, it commits it and starts a new one.

func (*TxConn) Commit

func (txc *TxConn) Commit(ctx context.Context, session *SafeSession) error

Commit commits the current transaction. The type of commit can be best effort or 2pc depending on the session setting.

func (*TxConn) Release

func (txc *TxConn) Release(ctx context.Context, session *SafeSession) error

Release releases the reserved connection and/or rollbacks the transaction

func (*TxConn) ReleaseAll added in v0.8.0

func (txc *TxConn) ReleaseAll(ctx context.Context, session *SafeSession) error

ReleaseAll releases all the shard sessions and lock session.

func (*TxConn) ReleaseLock added in v0.8.0

func (txc *TxConn) ReleaseLock(ctx context.Context, session *SafeSession) error

ReleaseLock releases the reserved connection used for locking.

func (*TxConn) Resolve

func (txc *TxConn) Resolve(ctx context.Context, dtid string) error

Resolve resolves the specified 2PC transaction.

func (*TxConn) Rollback

func (txc *TxConn) Rollback(ctx context.Context, session *SafeSession) error

Rollback rolls back the current transaction. There are no retries on this operation.

type VSchemaKeyspaceStats

type VSchemaKeyspaceStats struct {
	Keyspace    string
	Sharded     bool
	TableCount  int
	VindexCount int
	Error       string
}

VSchemaKeyspaceStats contains a rollup of the VSchema stats for a keyspace. It is used to display a table with the information in the status page.

type VSchemaManager

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

VSchemaManager is used to watch for updates to the vschema and to implement the DDL commands to add / remove vindexes

func (*VSchemaManager) GetCurrentSrvVschema

func (vm *VSchemaManager) GetCurrentSrvVschema() *vschemapb.SrvVSchema

GetCurrentSrvVschema returns a copy of the latest SrvVschema from the topo watch

func (*VSchemaManager) Rebuild added in v0.11.0

func (vm *VSchemaManager) Rebuild()

Rebuild will rebuild and publish the new vschema. This method should be called when the underlying schema has changed.

func (*VSchemaManager) UpdateVSchema

func (vm *VSchemaManager) UpdateVSchema(ctx context.Context, ksName string, vschema *vschemapb.SrvVSchema) error

UpdateVSchema propagates the updated vschema to the topo. The entry for the given keyspace is updated in the global topo, and the full SrvVSchema is updated in all known cells.

func (*VSchemaManager) VSchemaUpdate added in v0.11.0

func (vm *VSchemaManager) VSchemaUpdate(v *vschemapb.SrvVSchema, err error)

VSchemaUpdate builds the VSchema from SrvVschema and call subscribers.

type VSchemaOperator

type VSchemaOperator interface {
	GetCurrentSrvVschema() *vschemapb.SrvVSchema
	UpdateVSchema(ctx context.Context, ksName string, vschema *vschemapb.SrvVSchema) error
}

VSchemaOperator is an interface to Vschema Operations

type VSchemaStats

type VSchemaStats struct {
	Error     string
	Keyspaces []*VSchemaKeyspaceStats
}

VSchemaStats contains a rollup of the VSchema stats.

func NewVSchemaStats

func NewVSchemaStats(vschema *vindexes.VSchema, errorMessage string) *VSchemaStats

NewVSchemaStats returns a new VSchemaStats from a VSchema.

type VTGate

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

VTGate is the rpc interface to vtgate. Only one instance can be created. It implements vtgateservice.VTGateService VTGate exposes multiple generations of interfaces.

func Init

func Init(ctx context.Context, serv srvtopo.Server, cell string, tabletTypesToWait []topodatapb.TabletType) *VTGate

Init initializes VTGate server.

func LegacyInit

func LegacyInit(ctx context.Context, hc discovery.LegacyHealthCheck, serv srvtopo.Server, cell string, retryCount int, tabletTypesToWait []topodatapb.TabletType) *VTGate

LegacyInit initializes VTGate server with LegacyHealthCheck

func (*VTGate) CloseSession

func (vtg *VTGate) CloseSession(ctx context.Context, session *vtgatepb.Session) error

CloseSession closes the session, rolling back any implicit transactions. This has the same effect as if a "rollback" statement was executed, but does not affect the query statistics.

func (*VTGate) Execute

func (vtg *VTGate) Execute(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable) (newSession *vtgatepb.Session, qr *sqltypes.Result, err error)

Execute executes a non-streaming query. This is a V3 function.

func (*VTGate) ExecuteBatch

func (vtg *VTGate) ExecuteBatch(ctx context.Context, session *vtgatepb.Session, sqlList []string, bindVariablesList []map[string]*querypb.BindVariable) (*vtgatepb.Session, []sqltypes.QueryResponse, error)

ExecuteBatch executes a batch of queries. This is a V3 function.

func (*VTGate) Gateway

func (vtg *VTGate) Gateway() Gateway

Gateway returns the current gateway implementation. Mostly used for tests.

func (*VTGate) GetGatewayCacheStatus

func (vtg *VTGate) GetGatewayCacheStatus() TabletCacheStatusList

GetGatewayCacheStatus returns a displayable version of the Gateway cache.

func (*VTGate) HandlePanic

func (vtg *VTGate) HandlePanic(err *error)

HandlePanic recovers from panics, and logs / increment counters

func (*VTGate) IsHealthy

func (vtg *VTGate) IsHealthy() error

IsHealthy returns nil if server is healthy. Otherwise, it returns an error indicating the reason.

func (*VTGate) Prepare

func (vtg *VTGate) Prepare(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable) (newSession *vtgatepb.Session, fld []*querypb.Field, err error)

Prepare supports non-streaming prepare statement query with multi shards

func (*VTGate) ResolveTransaction

func (vtg *VTGate) ResolveTransaction(ctx context.Context, dtid string) error

ResolveTransaction resolves the specified 2PC transaction.

func (*VTGate) StreamExecute

func (vtg *VTGate) StreamExecute(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable, callback func(*sqltypes.Result) error) error

StreamExecute executes a streaming query. This is a V3 function. Note we guarantee the callback will not be called concurrently by multiple go routines.

func (*VTGate) VSchemaStats

func (vtg *VTGate) VSchemaStats() *VSchemaStats

VSchemaStats returns the loaded vschema stats.

func (*VTGate) VStream

func (vtg *VTGate) VStream(ctx context.Context, tabletType topodatapb.TabletType, vgtid *binlogdatapb.VGtid, filter *binlogdatapb.Filter, flags *vtgatepb.VStreamFlags, send func([]*binlogdatapb.VEvent) error) error

VStream streams binlog events.

Directories

Path Synopsis
Package buffer provides a buffer for MASTER traffic during failovers.
Package buffer provides a buffer for MASTER traffic during failovers.
Package fakerpcvtgateconn provides a fake implementation of vtgateconn.Impl that doesn't do any RPC, but uses a local map to return results.
Package fakerpcvtgateconn provides a fake implementation of vtgateconn.Impl that doesn't do any RPC, but uses a local map to return results.
Package grpcvtgateconn provides gRPC connectivity for VTGate.
Package grpcvtgateconn provides gRPC connectivity for VTGate.
Package grpcvtgateservice provides the gRPC glue for vtgate
Package grpcvtgateservice provides the gRPC glue for vtgate
Package planbuilder allows you to build execution plans that describe how to fulfill a query that may span multiple keyspaces or shards.
Package planbuilder allows you to build execution plans that describe how to fulfill a query that may span multiple keyspaces or shards.
Package vtgateservice provides to interface definition for the vtgate service
Package vtgateservice provides to interface definition for the vtgate service

Jump to

Keyboard shortcuts

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