vexec

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// VExecTableQualifier is the qualifier that all tables supported by vexec
	// are prefixed by.
	VExecTableQualifier = "_vt"

	// SchemaMigrationsTableName is the unqualified name of the schema
	// migrations table supported by vexec.
	SchemaMigrationsTableName = "schema_migrations"
	// VReplicationTableName is the unqualified name of the vreplication table
	// supported by vexec.
	VReplicationTableName = "vreplication"
)

Variables

View Source
var (
	// ErrCannotUpdateImmutableColumn is returned when attempting to plan a
	// query that updates a column that should be treated as immutable.
	ErrCannotUpdateImmutableColumn = errors.New("cannot update immutable column")
	// ErrUnsupportedQueryConstruct is returned when a particular query
	// construct is unsupported by a QueryPlanner, despite the more general kind
	// of query being supported.
	//
	// For example, VReplication supports DELETEs, but does not support DELETEs
	// with LIMIT clauses, so planning a "DELETE ... LIMIT" will return
	// ErrUnsupportedQueryConstruct rather than a "CREATE TABLE", which would
	// return an ErrUnsupportedQuery.
	ErrUnsupportedQueryConstruct = errors.New("unsupported query construct")
)
View Source
var (
	// ErrNoShardPrimary occurs when a shard is found with no serving
	// primary.
	ErrNoShardPrimary = errors.New("no primary found for shard")
	// ErrNoShardsForKeyspace occurs when attempting to run a vexec on an empty
	// keyspace.
	ErrNoShardsForKeyspace = errors.New("no shards found in keyspace")
)
View Source
var (
	// ErrUnsupportedQuery occurs when attempting to run an unsupported query
	// through vexec.
	ErrUnsupportedQuery = errors.New("query not supported by vexec")
	// ErrUnsupportedTable occurs when attempting to run vexec on an unsupported
	// table. At the time of writing, this occurs when attempting to query any
	// table other than _vt.vreplication.
	ErrUnsupportedTable = errors.New("table not supported by vexec")
)
View Source
var (
	// ErrUnpreparedQuery is returned when attempting to execute an unprepared
	// QueryPlan.
	ErrUnpreparedQuery = errors.New("attempted to execute unprepared query")
)

Functions

This section is empty.

Types

type QueryParams

type QueryParams struct {
	// DBName is the value that the column referred to by DBNameColumn should
	// equal in a WHERE clause, if set.
	DBName string
	// DBNameColumn is the name of the column that DBName should equal in a
	// WHERE clause, if set.
	DBNameColumn string
	// Workflow is the value that the column referred to by WorkflowColumn
	// should equal in a WHERE clause, if set.
	Workflow string
	// WorkflowColumn is the name of the column that Workflow should equal in a
	// WHERE clause, if set.
	WorkflowColumn string
}

QueryParams is a struct that QueryPlanner implementations can provide to control the addition of default WHERE clauses to their queries.

type QueryPlan

type QueryPlan struct {
	ParsedQuery *sqlparser.ParsedQuery
	// contains filtered or unexported fields
}

QueryPlan wraps a planned query produced by a QueryPlanner. It is safe to execute a QueryPlan repeatedly and in multiple goroutines.

func (*QueryPlan) Execute

func (qp *QueryPlan) Execute(ctx context.Context, target *topo.TabletInfo) (qr *querypb.QueryResult, err error)

Execute executes a QueryPlan on a single target.

func (*QueryPlan) ExecuteScatter

func (qp *QueryPlan) ExecuteScatter(ctx context.Context, targets ...*topo.TabletInfo) (map[*topo.TabletInfo]*querypb.QueryResult, error)

ExecuteScatter executes a QueryPlan on multiple targets concurrently, returning a mapping of target tablet to querypb.QueryResult. Errors from individual targets are aggregated into a singular error.

type QueryPlanner

type QueryPlanner interface {

	// PlanQuery constructs and returns a QueryPlan for a given statement. The
	// resulting QueryPlan is suitable for repeated, concurrent use.
	PlanQuery(stmt sqlparser.Statement) (*QueryPlan, error)
	// QueryParams returns a struct of column parameters the QueryPlanner uses.
	// It is used primarily to abstract the adding of default WHERE clauses to
	// queries by a private function of this package, and may be removed from
	// the interface later.
	QueryParams() QueryParams
}

QueryPlanner defines the interface that VExec uses to build QueryPlans for various vexec workflows. A given vexec table, which is to say a table in the "_vt" database, will have at most one QueryPlanner implementation, which is responsible for defining both what queries are supported for that table, as well as how to build plans for those queries.

VReplicationQueryPlanner is a good example implementation to refer to.

type VExec

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

VExec provides the main interface to planning and executing vexec queries (normally, queries on tables in the `_vt` database). It currently supports some limited vreplication queries; this set of supported behavior will expand over time. It may be extended to support schema_migrations queries as well.

func NewVExec

func NewVExec(keyspace string, workflow string, ts *topo.Server, tmc tmclient.TabletManagerClient) *VExec

NewVExec returns a new instance suitable for making vexec queries to a given keyspace (required) and workflow (optional, omit by providing the empty string). The provided topo server is used to look up target tablets for queries. A given instance will discover targets exactly once for its lifetime, so to force a refresh, create another instance.

func (*VExec) GetPlanner

func (vx *VExec) GetPlanner(ctx context.Context, table string) (QueryPlanner, error)

GetPlanner returns an appropriate implementation of a QueryPlanner, depending on the table being queried.

On first use, GetPlanner will also cause the VExec instance to discover target tablets from the topo; that target list will be reused for all future queries made by this instance.

func (*VExec) QueryContext

func (vx *VExec) QueryContext(ctx context.Context, query string) (map[*topo.TabletInfo]*querypb.QueryResult, error)

QueryContext executes the given vexec query, returning a mapping of tablet to querypb.QueryResult.

On first use, QueryContext will also cause the VExec instance to discover target tablets from the topo; that target list will be reused for all future queries made by this instance.

For details on query parsing and planning, see GetPlanner and the QueryPlanner interface.

type VReplicationQueryPlanner

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

VReplicationQueryPlanner implements the QueryPlanner interface for queries on the _vt.vreplication table.

func NewVReplicationQueryPlanner

func NewVReplicationQueryPlanner(tmc tmclient.TabletManagerClient, workflow string, dbname string) *VReplicationQueryPlanner

NewVReplicationQueryPlanner returns a new VReplicationQueryPlanner. It is valid to pass empty strings for both the dbname and workflow parameters.

func (*VReplicationQueryPlanner) PlanQuery

func (planner *VReplicationQueryPlanner) PlanQuery(stmt sqlparser.Statement) (plan *QueryPlan, err error)

PlanQuery is part of the QueryPlanner interface.

For vreplication query planners, only SELECT, UPDATE, and DELETE queries are supported.

For UPDATE queries, ORDER BY and LIMIT clauses are not supported. Attempting to update vreplication.id is an error.

For DELETE queries, USING, PARTITION, ORDER BY, and LIMIT clauses are not supported.

func (*VReplicationQueryPlanner) QueryParams

func (planner *VReplicationQueryPlanner) QueryParams() QueryParams

QueryParams is part of the QueryPlanner interface. A VReplicationQueryPlanner will attach the following WHERE clauses iff (a) DBName, Workflow are set, respectively, and (b) db_name and workflow do not appear in the original query's WHERE clause:

WHERE (db_name = {{ .DBName }} AND)? (workflow = {{ .Workflow }} AND)? {{ .OriginalWhere }}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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