tabletconn

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2016 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConnClosed is returned when the underlying connection was closed.
	ConnClosed = OperationalError("vttablet: Connection Closed")
)

Variables

View Source
var (
	// TabletProtocol is exported for unit tests
	TabletProtocol = flag.String("tablet_protocol", "grpc", "how to talk to the vttablets")
)

Functions

func RegisterDialer

func RegisterDialer(name string, dialer TabletDialer)

RegisterDialer is meant to be used by TabletDialer implementations to self register.

func TabletErrorFromGRPC

func TabletErrorFromGRPC(err error) error

TabletErrorFromGRPC returns a ServerError or a OperationalError from the gRPC error.

func TabletErrorFromRPCError

func TabletErrorFromRPCError(err *vtrpcpb.RPCError) error

TabletErrorFromRPCError returns a ServerError from a vtrpcpb.ServerError

Types

type OperationalError

type OperationalError string

OperationalError represents an error due to a failure to communicate with vttablet.

func (OperationalError) Error

func (e OperationalError) Error() string

type ServerError

type ServerError struct {
	Err string
	// ServerCode is the error code that we got from the server.
	ServerCode vtrpcpb.ErrorCode
}

ServerError represents an error that was returned from a vttablet server. it implements vterrors.VtError.

func (*ServerError) Error

func (e *ServerError) Error() string

func (*ServerError) VtErrorCode

func (e *ServerError) VtErrorCode() vtrpcpb.ErrorCode

VtErrorCode returns the underlying Vitess error code. This makes ServerError implement vterrors.VtError.

type StreamHealthReader

type StreamHealthReader interface {
	// Recv reads one StreamHealthResponse.
	Recv() (*querypb.StreamHealthResponse, error)
}

StreamHealthReader defines the interface for a reader to read StreamHealth messages.

type TabletConn

type TabletConn interface {
	// Execute executes a non-streaming query on vttablet.
	Execute(ctx context.Context, query string, bindVars map[string]interface{}, transactionID int64) (*sqltypes.Result, error)

	// ExecuteBatch executes a group of queries.
	ExecuteBatch(ctx context.Context, queries []querytypes.BoundQuery, asTransaction bool, transactionID int64) ([]sqltypes.Result, error)

	// StreamExecute executes a streaming query on vttablet. It
	// returns a sqltypes.ResultStream to get results from. If
	// error is non-nil, it means that the StreamExecute failed to
	// send the request. Otherwise, you can pull values from the
	// ResultStream until io.EOF, or any other error.
	StreamExecute(ctx context.Context, query string, bindVars map[string]interface{}) (sqltypes.ResultStream, error)

	// Transaction support
	Begin(ctx context.Context) (transactionID int64, err error)
	Commit(ctx context.Context, transactionID int64) error
	Rollback(ctx context.Context, transactionID int64) error

	// Combo RPC calls: they execute both a Begin and another call.
	// Note even if error is set, transactionID may be returned
	// and different than zero, if the Begin part worked.
	BeginExecute(ctx context.Context, query string, bindVars map[string]interface{}) (result *sqltypes.Result, transactionID int64, err error)
	BeginExecuteBatch(ctx context.Context, queries []querytypes.BoundQuery, asTransaction bool) (results []sqltypes.Result, transactionID int64, err error)

	// Close must be called for releasing resources.
	Close()

	// SetTarget can be called to change the target used for
	// subsequent calls.
	SetTarget(keyspace, shard string, tabletType topodatapb.TabletType) error

	// Tablet returns the tablet info.
	Tablet() *topodatapb.Tablet

	// SplitQuery splits a query into equally sized smaller queries by
	// appending primary key range clauses to the original query
	SplitQuery(ctx context.Context, query querytypes.BoundQuery, splitColumn string, splitCount int64) ([]querytypes.QuerySplit, error)

	// SplitQuery splits a query into equally sized smaller queries by
	// appending primary key range clauses to the original query
	// TODO(erez): Remove SplitQuery and rename this to SplitQueryV2 once migration is done.
	SplitQueryV2(
		ctx context.Context,
		query querytypes.BoundQuery,
		splitColumns []string,
		splitCount int64,
		numRowsPerQueryPart int64,
		algorithm querypb.SplitQueryRequest_Algorithm) (queries []querytypes.QuerySplit, err error)

	// StreamHealth starts a streaming RPC for VTTablet health status updates.
	StreamHealth(ctx context.Context) (StreamHealthReader, error)
}

TabletConn defines the interface for a vttablet client. It should be thread-safe, so it can be used concurrently used across goroutines.

Most RPC functions can return: - tabletconn.ConnClosed if the underlying connection was closed. - context.Canceled if the query was canceled by the user.

type TabletDialer

type TabletDialer func(ctx context.Context, tablet *topodatapb.Tablet, timeout time.Duration) (TabletConn, error)

TabletDialer represents a function that will return a TabletConn object that can communicate with a tablet.

The Tablet's keyspace, shard and tabletType are remembered and used as Target. Use SetTarget to update them later. If the TabletDialer is used for StreamHealth only, then the tablet's keyspace, shard and tabletType won't be used.

func GetDialer

func GetDialer() TabletDialer

GetDialer returns the dialer to use, described by the command line flag

Jump to

Keyboard shortcuts

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