Documentation ¶
Overview ¶
Package queryservice contains the interface for the service definition of the Query Service.
Index ¶
- func ExecuteWithStreamer(ctx context.Context, conn QueryService, target *querypb.Target, sql string, ...) sqltypes.ResultStream
- func ExecuteWithTransactionalStreamer(ctx context.Context, conn QueryService, target *querypb.Target, sql string, ...) sqltypes.ResultStream
- type QueryService
- type WrapperFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecuteWithStreamer ¶
func ExecuteWithStreamer(ctx context.Context, conn QueryService, target *querypb.Target, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) sqltypes.ResultStream
ExecuteWithStreamer performs a StreamExecute, but returns a *sqltypes.ResultStream to iterate on. This function should only be used for legacy code. New usage should directly use StreamExecute.
func ExecuteWithTransactionalStreamer ¶
func ExecuteWithTransactionalStreamer(ctx context.Context, conn QueryService, target *querypb.Target, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions) sqltypes.ResultStream
ExecuteWithTransactionalStreamer does the same thing as ExecuteWithStreamer, but inside a transaction
Types ¶
type QueryService ¶
type QueryService interface { // Begin returns the transaction id to use for further operations Begin(ctx context.Context, target *querypb.Target, options *querypb.ExecuteOptions) (int64, *topodatapb.TabletAlias, error) // Commit commits the current transaction Commit(ctx context.Context, target *querypb.Target, transactionID int64) (int64, error) // Rollback aborts the current transaction Rollback(ctx context.Context, target *querypb.Target, transactionID int64) (int64, error) // Prepare prepares the specified transaction. Prepare(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error) // CommitPrepared commits the prepared transaction. CommitPrepared(ctx context.Context, target *querypb.Target, dtid string) (err error) // RollbackPrepared rolls back the prepared transaction. RollbackPrepared(ctx context.Context, target *querypb.Target, dtid string, originalID int64) (err error) // CreateTransaction creates the metadata for a 2PC transaction. CreateTransaction(ctx context.Context, target *querypb.Target, dtid string, participants []*querypb.Target) (err error) // StartCommit atomically commits the transaction along with the // decision to commit the associated 2pc transaction. StartCommit(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error) // SetRollback transitions the 2pc transaction to the Rollback state. // If a transaction id is provided, that transaction is also rolled back. SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error) // ConcludeTransaction deletes the 2pc transaction metadata // essentially resolving it. ConcludeTransaction(ctx context.Context, target *querypb.Target, dtid string) (err error) // ReadTransaction returns the metadata for the specified dtid. ReadTransaction(ctx context.Context, target *querypb.Target, dtid string) (metadata *querypb.TransactionMetadata, err error) // Query execution Execute(ctx context.Context, target *querypb.Target, sql string, bindVariables map[string]*querypb.BindVariable, transactionID, reservedID int64, options *querypb.ExecuteOptions) (*sqltypes.Result, error) // Currently always called with transactionID = 0 StreamExecute(ctx context.Context, target *querypb.Target, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) error // Currently always called with transactionID = 0 ExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, asTransaction bool, transactionID int64, options *querypb.ExecuteOptions) ([]sqltypes.Result, error) // Combo methods, they also return the transactionID from the // Begin part. If err != nil, the transactionID may still be // non-zero, and needs to be propagated back (like for a DB // Integrity Error) BeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, reservedID int64, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error) BeginExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, asTransaction bool, options *querypb.ExecuteOptions) ([]sqltypes.Result, int64, *topodatapb.TabletAlias, error) // Messaging methods. MessageStream(ctx context.Context, target *querypb.Target, name string, callback func(*sqltypes.Result) error) error MessageAck(ctx context.Context, target *querypb.Target, name string, ids []*querypb.Value) (count int64, err error) // VStream streams VReplication events based on the specified filter. VStream(ctx context.Context, target *querypb.Target, startPos string, tableLastPKs []*binlogdatapb.TableLastPK, filter *binlogdatapb.Filter, send func([]*binlogdatapb.VEvent) error) error // VStreamRows streams rows of a table from the specified starting point. VStreamRows(ctx context.Context, target *querypb.Target, query string, lastpk *querypb.QueryResult, send func(*binlogdatapb.VStreamRowsResponse) error) error // VStreamResults streams results along with the gtid of the snapshot. VStreamResults(ctx context.Context, target *querypb.Target, query string, send func(*binlogdatapb.VStreamResultsResponse) error) error // StreamHealth streams health status. StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error // HandlePanic will be called if any of the functions panic. HandlePanic(err *error) ReserveBeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, int64, *topodatapb.TabletAlias, error) ReserveExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error) Release(ctx context.Context, target *querypb.Target, transactionID, reservedID int64) error // Close must be called for releasing resources. Close(ctx context.Context) error }
QueryService is the interface implemented by the tablet's query service. All streaming methods accept a callback function that will be called for each response. If the callback returns an error, that error is returned back by the function, except in the case of io.EOF in which case the stream will be terminated with no error. Streams can also be terminated by canceling the context. This API is common for both server and client implementations. All functions must be safe to be called concurrently.
func Wrap ¶
func Wrap(impl QueryService, wrapper WrapperFunc) QueryService
Wrap returns a wrapped version of the original QueryService implementation. This lets you avoid repeating boiler-plate code by consolidating it in the wrapper function. A good example of this is go/vt/vtgate/gateway/discoverygateway.go. For every method invocation, the wrapper function is called, which can in turn call the provided inner function that will use the input parameters to call the implementation. In order to load balance across multiple implementations, you can set impl to be nil and provide the connection as input to the action function. In the case of StreamHealth or Close, there is no target and it will be nil. If necessary, the wrapper can validate the nil against the method name. The wrapper is also responsible for calling HandlePanic where necessary.
type WrapperFunc ¶
type WrapperFunc func(ctx context.Context, target *querypb.Target, conn QueryService, name string, inTransaction bool, inner func(context.Context, *querypb.Target, QueryService) (canRetry bool, err error)) error
WrapperFunc defines the signature for the wrapper function used by Wrap. Parameter ordering is as follows: original parameters, connection, method name, additional parameters and inner func. The inner function returns err and canRetry. If canRetry is true, the error is specific to the current vttablet and can be retried elsewhere. The flag will be false if there was no error.