control

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package control controls which resources a query may consume.

The Controller manages the resources available to each query and ensures an optimal use of those resources to execute queries in a timely manner. The controller also maintains the state of a query as it goes through the various stages of execution and is responsible for killing currently executing queries when requested by the user.

The Controller manages when a query is executed. This can be based on anything within the query's requested resources. For example, a basic implementation of the Controller may decide to execute anything with a high priority before anything with a low priority. The implementation of the Controller will vary and change over time and this package may provide multiple implementations for different controller algorithms.

During execution, the Controller manages the resources used by the query and provides observabiility into what resources are being used and by which queries. The Controller also imposes limitations so a query that uses more than its allocated resources or more resources than available on the system will be aborted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartSpanFromContext

func StartSpanFromContext(ctx context.Context, operationName string, hist prometheus.Observer, gauge prometheus.Gauge) (*span, context.Context)

Types

type Config

type Config struct {
	ConcurrencyQuota     int
	MemoryBytesQuota     int64
	ExecutorDependencies execute.Dependencies
	PPlannerOptions      []plan.PhysicalOption
	LPlannerOptions      []plan.LogicalOption
	Logger               *zap.Logger
	// MetricLabelKeys is a list of labels to add to the metrics produced by the controller.
	// The value for a given key will be read off the context.
	// The context value must be a string or an implementation of the Stringer interface.
	MetricLabelKeys []string
}

type Controller

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

Controller provides a central location to manage all incoming queries. The controller is responsible for queueing, planning, and executing queries.

func New

func New(c Config) *Controller

func (*Controller) CancelAll added in v0.10.0

func (c *Controller) CancelAll()

CancelAll cancels all executing queries.

func (*Controller) PrometheusCollectors

func (c *Controller) PrometheusCollectors() []prometheus.Collector

PrometheusCollectors satisifies the prom.PrometheusCollector interface.

func (*Controller) Queries

func (c *Controller) Queries() []*Query

Queries reports the active queries.

func (*Controller) Query

func (c *Controller) Query(ctx context.Context, compiler flux.Compiler) (flux.Query, error)

Query submits a query for execution returning immediately. Done must be called on any returned Query objects.

func (*Controller) Shutdown added in v0.7.1

func (c *Controller) Shutdown(ctx context.Context) error

Shutdown will signal to the Controller that it should not accept any new queries and that it should finish executing any existing queries. This will return once the Controller's run loop has been exited and all queries have been finished or until the Context has been canceled.

type PriorityQueue

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

func (*PriorityQueue) Peek

func (p *PriorityQueue) Peek() *Query

func (*PriorityQueue) Pop

func (p *PriorityQueue) Pop() *Query

func (*PriorityQueue) Push

func (p *PriorityQueue) Push(q *Query)

type Query

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

Query represents a single request.

func (*Query) Cancel

func (q *Query) Cancel()

Cancel will stop the query execution.

func (*Query) Concurrency

func (q *Query) Concurrency() int

Concurrency reports the number of goroutines allowed to process the request.

func (*Query) Done

func (q *Query) Done()

Done signals to the Controller that this query is no longer being used and resources related to the query may be freed.

The Ready method must have returned a result before calling this method either by the query executing, being canceled, or an error occurring.

func (*Query) Err

func (q *Query) Err() error

Err reports any error the query may have encountered.

func (*Query) ID

func (q *Query) ID() QueryID

ID reports an ephemeral unique ID for the query.

func (*Query) Ready

func (q *Query) Ready() <-chan map[string]flux.Result

Ready returns a channel that will deliver the query results.

It's possible that the channel is closed before any results arrive. In particular, if a query's context or the query itself is canceled, the query may close the results channel before any results are computed.

The query may also have an error during execution so the Err() function should be used to check if an error happened.

func (*Query) Spec

func (q *Query) Spec() *flux.Spec

func (*Query) State

func (q *Query) State() State

State reports the current state of the query.

func (*Query) Statistics

func (q *Query) Statistics() flux.Statistics

Statistics reports the statistics for the query.

This method must be called after Done. It will block until the query has been finalized unless a context is given.

type QueryID

type QueryID uint64

type State

type State int

State is the query state.

const (
	// Created indicates the query has been created.
	Created State = iota

	// Compiling indicates that the query is in the process
	// of executing the compiler associated with the query.
	Compiling

	// Planning indicates that a query spec has been created
	// from the compiler and the query planner is executing.
	Planning

	// Queueing indicates the query is waiting inside of the
	// scheduler to be executed.
	Queueing

	// Requeueing indicates that the query scheduler wanted
	// to run the query, but not enough resources were available
	// so it is in the process of waiting again.
	Requeueing

	// Executing indicates that the query is currently executing.
	Executing

	// Errored indicates that there was an error when attempting
	// to execute a query within any state inside of the controller.
	Errored

	// Finished indicates that the query has been marked as Done
	// and it is awaiting removal from the Controller or has already
	// been removed.
	Finished

	// Canceled indicates that the query was signaled to be
	// canceled. A canceled query must still be released with Done.
	Canceled
)

func (State) String

func (s State) String() string

type Stringer

type Stringer interface {
	String() string
}

Directories

Path Synopsis
Package controltest provides a controller for use in tests.
Package controltest provides a controller for use in tests.

Jump to

Keyboard shortcuts

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