vtgateconn

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 9 Imported by: 23

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// VtgateProtocol defines the RPC implementation used for connecting to vtgate.
	VtgateProtocol = flag.String("vtgate_protocol", "grpc", "how to talk to vtgate")
)

Functions

func RegisterDialer

func RegisterDialer(name string, dialer DialerFunc)

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

Types

type DialerFunc

type DialerFunc func(ctx context.Context, address string) (Impl, error)

DialerFunc represents a function that will return an Impl object that can communicate with a VTGate.

type Impl

type Impl interface {
	// Execute executes a non-streaming query on vtgate. This is a V3 function.
	Execute(ctx context.Context, session *vtgatepb.Session, query string, bindVars map[string]*querypb.BindVariable) (*vtgatepb.Session, *sqltypes.Result, error)

	// ExecuteBatch executes a non-streaming queries on vtgate. This is a V3 function.
	ExecuteBatch(ctx context.Context, session *vtgatepb.Session, queryList []string, bindVarsList []map[string]*querypb.BindVariable) (*vtgatepb.Session, []sqltypes.QueryResponse, error)

	// StreamExecute executes a streaming query on vtgate. This is a V3 function.
	StreamExecute(ctx context.Context, session *vtgatepb.Session, query string, bindVars map[string]*querypb.BindVariable) (sqltypes.ResultStream, error)

	// Prepare returns the fields information for the query as part of supporting prepare statements.
	Prepare(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable) (*vtgatepb.Session, []*querypb.Field, error)

	// CloseSession closes the session provided by rolling back any active transaction.
	CloseSession(ctx context.Context, session *vtgatepb.Session) error

	// ResolveTransaction resolves the specified 2pc transaction.
	ResolveTransaction(ctx context.Context, dtid string) error

	// VStream streams binlogevents
	VStream(ctx context.Context, tabletType topodatapb.TabletType, vgtid *binlogdatapb.VGtid, filter *binlogdatapb.Filter, flags *vtgatepb.VStreamFlags) (VStreamReader, error)

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

Impl defines the interface for a vtgate client protocol implementation. It can be used concurrently across goroutines.

type VStreamReader

type VStreamReader interface {
	// Recv returns the next result on the stream.
	// It will return io.EOF if the stream ended.
	Recv() ([]*binlogdatapb.VEvent, error)
}

VStreamReader is returned by VStream.

type VTGateConn

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

VTGateConn is the client API object to talk to vtgate. It can support concurrent sessions. It is constructed using the Dial method.

func Dial

func Dial(ctx context.Context, address string) (*VTGateConn, error)

Dial dials using the command-line specified protocol, and returns the *VTGateConn.

func DialProtocol

func DialProtocol(ctx context.Context, protocol string, address string) (*VTGateConn, error)

DialProtocol dials a specific protocol, and returns the *VTGateConn

func (*VTGateConn) Close

func (conn *VTGateConn) Close()

Close must be called for releasing resources.

func (*VTGateConn) ResolveTransaction

func (conn *VTGateConn) ResolveTransaction(ctx context.Context, dtid string) error

ResolveTransaction resolves the 2pc transaction.

func (*VTGateConn) Session

func (conn *VTGateConn) Session(targetString string, options *querypb.ExecuteOptions) *VTGateSession

Session returns a VTGateSession that can be used to access V3 functions.

func (*VTGateConn) VStream

func (conn *VTGateConn) VStream(ctx context.Context, tabletType topodatapb.TabletType, vgtid *binlogdatapb.VGtid,
	filter *binlogdatapb.Filter, flags *vtgatepb.VStreamFlags) (VStreamReader, error)

VStream streams binlog events.

type VTGateSession

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

VTGateSession exposes the V3 API to the clients. The object maintains client-side state and is comparable to a native MySQL connection. For example, if you enable autocommit on a Session object, all subsequent calls will respect this. Functions within an object must not be called concurrently. You can create as many objects as you want. All of them will share the underlying connection to vtgate ("VTGateConn" object).

func (*VTGateSession) Execute

func (sn *VTGateSession) Execute(ctx context.Context, query string, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error)

Execute performs a VTGate Execute.

func (*VTGateSession) ExecuteBatch

func (sn *VTGateSession) ExecuteBatch(ctx context.Context, query []string, bindVars []map[string]*querypb.BindVariable) ([]sqltypes.QueryResponse, error)

ExecuteBatch executes a list of queries on vtgate within the current transaction.

func (*VTGateSession) Prepare added in v0.11.0

func (sn *VTGateSession) Prepare(ctx context.Context, query string, bindVars map[string]*querypb.BindVariable) ([]*querypb.Field, error)

Prepare performs a VTGate Prepare.

func (*VTGateSession) StreamExecute

func (sn *VTGateSession) StreamExecute(ctx context.Context, query string, bindVars map[string]*querypb.BindVariable) (sqltypes.ResultStream, error)

StreamExecute executes a streaming query on vtgate. It returns a ResultStream and an error. First check the error. Then you can pull values from the ResultStream until io.EOF, or another error.

Jump to

Keyboard shortcuts

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