vexec

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: 14 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"
	// VReplicationLogTableName is the unqualified name of the vreplication_log
	// table supported by vexec.
	VReplicationLogTableName = "vreplication_log"
	// 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 FixedQueryPlan added in v0.11.0

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

FixedQueryPlan wraps a planned query produced by a QueryPlanner. It executes the same query with the same bind vals, regardless of the target.

func (*FixedQueryPlan) Execute added in v0.11.0

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

Execute is part of the QueryPlan interface.

func (*FixedQueryPlan) ExecuteScatter added in v0.11.0

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

ExecuteScatter is part of the QueryPlan interface. For a FixedQueryPlan, the exact same query is executed on each target, and errors from individual targets are aggregated into a singular error.

type PerTargetQueryPlan added in v0.11.0

type PerTargetQueryPlan struct {
	ParsedQueries map[string]*sqlparser.ParsedQuery
	// contains filtered or unexported fields
}

PerTargetQueryPlan implements the QueryPlan interface. Unlike FixedQueryPlan, this implementation implements different queries, keyed by tablet alias, on different targets.

It is the callers responsibility to ensure that the shape of the QueryResult (i.e. fields returned) is consistent for each target's planned query, but this is not enforced.

func (*PerTargetQueryPlan) Execute added in v0.11.0

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

Execute is part of the QueryPlan interface.

It returns ErrUnpreparedQuery if there is no ParsedQuery for the target's tablet alias.

func (*PerTargetQueryPlan) ExecuteScatter added in v0.11.0

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

ExecuteScatter is part of the QueryPlan interface.

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 interface {
	// Execute executes the planned query on a single target.
	Execute(ctx context.Context, target *topo.TabletInfo) (*querypb.QueryResult, error)
	// ExecuteScatter executes the planned query on the specified targets concurrently,
	// returning a mapping of the target tablet to a querypb.QueryResult.
	ExecuteScatter(ctx context.Context, targets ...*topo.TabletInfo) (map[*topo.TabletInfo]*querypb.QueryResult, error)
}

QueryPlan defines the interface to executing a preprared vexec query on one or more tablets. Implementations should ensure that it is safe to call the various Execute* methods repeatedly and in multiple goroutines.

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.

func (*VExec) WithWorkflow added in v0.11.0

func (vx *VExec) WithWorkflow(workflow string) *VExec

WithWorkflow returns a copy of VExec with the Workflow field updated. Used so callers to reuse a VExec's primaries list without needing to initialize a new VExec instance.

type VReplicationLogQueryPlanner added in v0.11.0

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

VReplicationLogQueryPlanner implements the QueryPlanner interface for queries on the _vt.vreplication_log table.

func NewVReplicationLogQueryPlanner added in v0.11.0

func NewVReplicationLogQueryPlanner(tmc tmclient.TabletManagerClient, tabletStreamIDs map[string][]int64) *VReplicationLogQueryPlanner

NewVReplicationLogQueryPlanner returns a new VReplicationLogQueryPlanner. The tabletStreamIDs map determines what stream_ids are expected to have vrep_log rows, keyed by tablet alias string.

func (*VReplicationLogQueryPlanner) PlanQuery added in v0.11.0

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

PlanQuery is part of the QueryPlanner interface.

For vreplication_log query planners, only SELECT queries are supported.

func (*VReplicationLogQueryPlanner) QueryParams added in v0.11.0

func (planner *VReplicationLogQueryPlanner) QueryParams() QueryParams

QueryParams is part of 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