vtgate

package
v0.0.0-...-9a5932e Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2014 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package vtgate provides query routing rpc services for vttablets.

Index

Constants

This section is empty.

Variables

View Source
var RegisterVTGates []RegisterVTGate

Functions

func Init

func Init(serv SrvTopoServer, cell string, retryDelay time.Duration, retryCount int, timeout time.Duration)

Types

type Balancer

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

Balancer is a simple round-robin load balancer. It allows you to temporarily mark down nodes that are non-functional.

func NewBalancer

func NewBalancer(getEndPoints GetEndPointsFunc, retryDelay time.Duration) *Balancer

NewBalancer creates a Balancer. getAddreses is the function it will use to refresh the list of addresses if one of the nodes has been marked down. The list of addresses is shuffled. retryDelay specifies the minimum time a node will be marked down before it will be cleared for a retry.

func (*Balancer) Get

func (blc *Balancer) Get() (endPoint topo.EndPoint, err error)

Get returns a single endpoint that was not recently marked down. If it finds an address that was down for longer than retryDelay, it refreshes the list of addresses and returns the next available node. If all addresses are marked down, it waits and retries. If a refresh fails, it returns an error.

func (*Balancer) MarkDown

func (blc *Balancer) MarkDown(uid uint32)

MarkDown marks the specified address down. Such addresses will not be used by Balancer for the duration of retryDelay.

type GetEndPointsFunc

type GetEndPointsFunc func() (*topo.EndPoints, error)

type RegisterVTGate

type RegisterVTGate func(*VTGate)

registration mechanism

type ResilientSrvTopoServer

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

ResilientSrvTopoServer is an implementation of SrvTopoServer based on another SrvTopoServer that uses a cache for two purposes: - limit the QPS to the underlying SrvTopoServer - return the last known value of the data if there is an error

func NewResilientSrvTopoServer

func NewResilientSrvTopoServer(base SrvTopoServer) *ResilientSrvTopoServer

NewResilientSrvTopoServer creates a new ResilientSrvTopoServer based on the provided SrvTopoServer.

func (*ResilientSrvTopoServer) GetEndPoints

func (server *ResilientSrvTopoServer) GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error)

func (*ResilientSrvTopoServer) GetSrvKeyspace

func (server *ResilientSrvTopoServer) GetSrvKeyspace(cell, keyspace string) (*topo.SrvKeyspace, error)

func (*ResilientSrvTopoServer) GetSrvKeyspaceNames

func (server *ResilientSrvTopoServer) GetSrvKeyspaceNames(cell string) ([]string, error)

type SafeSession

type SafeSession struct {
	*proto.Session
	// contains filtered or unexported fields
}

func NewSafeSession

func NewSafeSession(sessn *proto.Session) *SafeSession

func (*SafeSession) Append

func (session *SafeSession) Append(shardSession *proto.ShardSession)

func (*SafeSession) Find

func (session *SafeSession) Find(keyspace, shard string, tabletType topo.TabletType) int64

func (*SafeSession) InTransaction

func (session *SafeSession) InTransaction() bool

func (*SafeSession) Reset

func (session *SafeSession) Reset()

type ScatterConn

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

ScatterConn is used for executing queries across multiple ShardConn connections.

func NewScatterConn

func NewScatterConn(serv SrvTopoServer, cell string, retryDelay time.Duration, retryCount int, timeout time.Duration) *ScatterConn

NewScatterConn creates a new ScatterConn. All input parameters are passed through for creating the appropriate ShardConn.

func (*ScatterConn) Close

func (stc *ScatterConn) Close() error

Close closes the underlying ShardConn connections.

func (*ScatterConn) Commit

func (stc *ScatterConn) Commit(context interface{}, session *SafeSession) (err error)

Commit commits the current transaction. There are no retries on this operation.

func (*ScatterConn) Execute

func (stc *ScatterConn) Execute(
	context interface{},
	query string,
	bindVars map[string]interface{},
	keyspace string,
	shards []string,
	tabletType topo.TabletType,
	session *SafeSession,
) (*mproto.QueryResult, error)

Execute executes a non-streaming query on the specified shards.

func (*ScatterConn) ExecuteBatch

func (stc *ScatterConn) ExecuteBatch(
	context interface{},
	queries []tproto.BoundQuery,
	keyspace string,
	shards []string,
	tabletType topo.TabletType,
	session *SafeSession,
) (qrs *tproto.QueryResultList, err error)

ExecuteBatch executes a batch of non-streaming queries on the specified shards.

func (*ScatterConn) Rollback

func (stc *ScatterConn) Rollback(context interface{}, session *SafeSession) (err error)

Rollback rolls back the current transaction. There are no retries on this operation.

func (*ScatterConn) StreamExecute

func (stc *ScatterConn) StreamExecute(
	context interface{},
	query string,
	bindVars map[string]interface{},
	keyspace string,
	shards []string,
	tabletType topo.TabletType,
	session *SafeSession,
	sendReply func(reply *mproto.QueryResult) error,
) error

StreamExecute executes a streaming query on vttablet. The retry rules are the same.

type ShardConn

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

ShardConn represents a load balanced connection to a group of vttablets that belong to the same shard. ShardConn can be concurrently used across goroutines. Such requests are interleaved on the same underlying connection.

func NewShardConn

func NewShardConn(serv SrvTopoServer, cell, keyspace, shard string, tabletType topo.TabletType, retryDelay time.Duration, retryCount int, timeout time.Duration) *ShardConn

NewShardConn creates a new ShardConn. It creates a Balancer using serv, cell, keyspace, tabletType and retryDelay. retryCount is the max number of retries before a ShardConn returns an error on an operation.

func (*ShardConn) Begin

func (sdc *ShardConn) Begin(context interface{}) (transactionId int64, err error)

Begin begins a transaction. The retry rules are the same as Execute.

func (*ShardConn) Close

func (sdc *ShardConn) Close()

Close closes the underlying TabletConn. ShardConn can be reused after this because it opens connections on demand.

func (*ShardConn) Commit

func (sdc *ShardConn) Commit(context interface{}, transactionId int64) (err error)

Commit commits the current transaction. The retry rules are the same as Execute.

func (*ShardConn) Execute

func (sdc *ShardConn) Execute(context interface{}, query string, bindVars map[string]interface{}, transactionId int64) (qr *mproto.QueryResult, err error)

Execute executes a non-streaming query on vttablet. If there are connection errors, it retries retryCount times before failing. It does not retry if the connection is in the middle of a transaction.

func (*ShardConn) ExecuteBatch

func (sdc *ShardConn) ExecuteBatch(context interface{}, queries []tproto.BoundQuery, transactionId int64) (qrs *tproto.QueryResultList, err error)

ExecuteBatch executes a group of queries. The retry rules are the same as Execute.

func (*ShardConn) Rollback

func (sdc *ShardConn) Rollback(context interface{}, transactionId int64) (err error)

Rollback rolls back the current transaction. The retry rules are the same as Execute.

func (*ShardConn) StreamExecute

func (sdc *ShardConn) StreamExecute(context interface{}, query string, bindVars map[string]interface{}, transactionId int64) (results <-chan *mproto.QueryResult, errFunc tabletconn.ErrFunc)

StreamExecute executes a streaming query on vttablet. The retry rules are the same as Execute.

func (*ShardConn) WrapError

func (sdc *ShardConn) WrapError(in error, conn tabletconn.TabletConn, inTransaction bool) (wrapped error)

WrapError returns ShardConnError which preserves the original error code if possible, adds the connection context and adds a bit to determine whether the keyspace/shard needs to be re-resolved for a potential sharding event.

type ShardConnError

type ShardConnError struct {
	Code            int
	ShardIdentifier string

	Err string
	// contains filtered or unexported fields
}

func (*ShardConnError) Error

func (e *ShardConnError) Error() string

type SrvTopoServer

type SrvTopoServer interface {
	GetSrvKeyspaceNames(cell string) ([]string, error)

	GetSrvKeyspace(cell, keyspace string) (*topo.SrvKeyspace, error)

	GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error)
}

SrvTopoServer is a subset of topo.Server that only contains the serving graph read-only calls used by clients to resolve serving addresses.

type VTGate

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

VTGate is the rpc interface to vtgate. Only one instance can be created.

var RpcVTGate *VTGate

func (*VTGate) Begin

func (vtg *VTGate) Begin(context interface{}, outSession *proto.Session) error

Begin begins a transaction. It has to be concluded by a Commit or Rollback.

func (*VTGate) Commit

func (vtg *VTGate) Commit(context interface{}, inSession *proto.Session) error

Commit commits a transaction.

func (*VTGate) ExecuteBatchShard

func (vtg *VTGate) ExecuteBatchShard(context interface{}, batchQuery *proto.BatchQueryShard, reply *proto.QueryResultList) error

ExecuteBatchShard executes a group of queries on the specified shards.

func (*VTGate) ExecuteShard

func (vtg *VTGate) ExecuteShard(context interface{}, query *proto.QueryShard, reply *proto.QueryResult) error

ExecuteShard executes a non-streaming query on the specified shards.

func (*VTGate) Rollback

func (vtg *VTGate) Rollback(context interface{}, inSession *proto.Session) error

Rollback rolls back a transaction.

func (*VTGate) StreamExecuteKeyRange

func (vtg *VTGate) StreamExecuteKeyRange(context interface{}, streamQuery *proto.StreamQueryKeyRange, sendReply func(*proto.QueryResult) error) error

StreamExecuteKeyRange executes a streaming query on the specified KeyRange. The KeyRange is resolved to shards using the serving graph. This function currently temporarily enforces the restriction of executing on one keyrange and one shard since it cannot merge-sort the results to guarantee ordering of response which is needed for checkpointing. The api supports supplying multiple keyranges to make it future proof.

func (*VTGate) StreamExecuteShard

func (vtg *VTGate) StreamExecuteShard(context interface{}, query *proto.QueryShard, sendReply func(*proto.QueryResult) error) error

StreamExecuteShard executes a streaming query on the specified shards.

Directories

Path Synopsis
Package gorpcvtgateservice provides to go rpc glue for vtgate
Package gorpcvtgateservice provides to go rpc glue for vtgate

Jump to

Keyboard shortcuts

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