vtgate

package
v0.0.0-...-7c5168d Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2013 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

This section is empty.

Functions

func Init

func Init(blm *BalancerMap, tabletProtocol string, retryDelay time.Duration, retryCount int)

func RegisterDialer

func RegisterDialer(name string, dialer TabletDialer)

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(getAddresses GetAddressesFunc, 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() (address string, err error)

Get returns a single address 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(address string)

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

type BalancerMap

type BalancerMap struct {
	Toposerv SubsetTopoServ
	Cell     string
	PortName string
	// contains filtered or unexported fields
}

BalancerMap builds and maintains a map from cell.keyspace.dbtype.shard to Balancers.

func NewBalancerMap

func NewBalancerMap(serv SubsetTopoServ, cell, namedPort string) *BalancerMap

NewBalancerMap builds a new BalancerMap. Each BalancerMap is dedicated to a cell. serv is the TopoServ used to fetch the list of tablets when needed. The Balancers will be built using the namedPort from each tablet info.

func (*BalancerMap) Balancer

func (blm *BalancerMap) Balancer(keyspace, shard string, tabletType topo.TabletType, retryDelay time.Duration) *Balancer

Balancer creates a Balancer if one doesn't exist for a cell.keyspace.dbtype.shard. If one was previously created, then that is returned. The retryDelay is used only when a Balancer is created.

type ErrFunc

type ErrFunc func() error

type GetAddressesFunc

type GetAddressesFunc func() ([]string, error)

type ScatterConn

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

ScatterConn is used for executing queries across multiple ShardConn connections.

func NewScatterConn

func NewScatterConn(blm *BalancerMap, tabletProtocol string, tabletType topo.TabletType, retryDelay time.Duration, retryCount int) *ScatterConn

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

func (*ScatterConn) Begin

func (stc *ScatterConn) Begin() error

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

func (*ScatterConn) Close

func (stc *ScatterConn) Close() error

Close closes the underlying ShardConn connections.

func (*ScatterConn) Commit

func (stc *ScatterConn) Commit() (err error)

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

func (*ScatterConn) Execute

func (stc *ScatterConn) Execute(query string, bindVars map[string]interface{}, keyspace string, shards []string) (*mproto.QueryResult, error)

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

func (*ScatterConn) ExecuteBatch

func (stc *ScatterConn) ExecuteBatch(queries []proto.BoundQuery, keyspace string, shards []string) (qrs *tproto.QueryResultList, err error)

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

func (*ScatterConn) Rollback

func (stc *ScatterConn) Rollback() (err error)

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

func (*ScatterConn) StreamExecute

func (stc *ScatterConn) StreamExecute(query string, bindVars map[string]interface{}, keyspace string, shards []string, sendReply func(reply interface{}) error) error

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

func (*ScatterConn) TransactionId

func (stc *ScatterConn) TransactionId() int64

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 should not be concurrently used across goroutines.

func NewShardConn

func NewShardConn(blm *BalancerMap, tabletProtocol, keyspace, shard string, tabletType topo.TabletType, retryDelay time.Duration, retryCount int) *ShardConn

NewShardConn creates a new ShardConn. It creates or reuses a Balancer from the supplied BalancerMap. retryDelay is as specified by Balancer. retryCount is the max number of retries before a ShardConn returns an error on an operation.

func (*ShardConn) Begin

func (sdc *ShardConn) Begin() (err error)

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

func (*ShardConn) Close

func (sdc *ShardConn) Close() error

Close closes the underlying vttablet connection.

func (*ShardConn) Commit

func (sdc *ShardConn) Commit() (err error)

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

func (*ShardConn) Execute

func (sdc *ShardConn) Execute(query string, bindVars map[string]interface{}) (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(queries []proto.BoundQuery) (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() (err error)

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

func (*ShardConn) StreamExecute

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

StreamExecute executes a streaming query on vttablet. The retry rules are the same as Execute. Calling other functions while streaming is not recommended.

func (*ShardConn) TransactionId

func (sdc *ShardConn) TransactionId() int64

func (*ShardConn) WrapError

func (sdc *ShardConn) WrapError(in error) (wrapped error)

WrapError adds the connection context to an error.

type SubsetTopoServ

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

SubsetTopoServ is a subset of topo.Server

type TabletBson

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

TabletBson implements a bson rpcplus implementation for TabletConn

func (*TabletBson) Begin

func (conn *TabletBson) Begin() error

func (*TabletBson) Close

func (conn *TabletBson) Close() error

func (*TabletBson) Commit

func (conn *TabletBson) Commit() error

func (*TabletBson) Execute

func (conn *TabletBson) Execute(query string, bindVars map[string]interface{}) (*mproto.QueryResult, error)

func (*TabletBson) ExecuteBatch

func (conn *TabletBson) ExecuteBatch(queries []proto.BoundQuery) (*tproto.QueryResultList, error)

func (*TabletBson) Rollback

func (conn *TabletBson) Rollback() error

func (*TabletBson) StreamExecute

func (conn *TabletBson) StreamExecute(query string, bindVars map[string]interface{}) (<-chan *mproto.QueryResult, ErrFunc)

func (*TabletBson) TransactionId

func (conn *TabletBson) TransactionId() int64

type TabletConn

type TabletConn interface {
	// Execute executes a non-streaming query on vttablet.
	Execute(query string, bindVars map[string]interface{}) (*mproto.QueryResult, error)

	// ExecuteBatch executes a group of queries.
	ExecuteBatch(queries []proto.BoundQuery) (*tproto.QueryResultList, error)

	// StreamExecute exectutes a streaming query on vttablet. It returns a channel that will stream results.
	// It also returns an ErrFunc that can be called to check if there were any errors. ErrFunc can be called
	// immediately after StreamExecute returns to check if there were errors sending the call. It should also
	// be called after finishing the iteration over the channel to see if there were other errors.
	StreamExecute(query string, bindVars map[string]interface{}) (<-chan *mproto.QueryResult, ErrFunc)

	// Transaction support
	Begin() error
	Commit() error
	Rollback() error
	// TransactionId returns 0 if there is no transaction.
	TransactionId() int64

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

TabletConn defines the interface for a vttablet client. It should not be concurrently used across goroutines.

func DialTablet

func DialTablet(addr, keyspace, shard, username, password string, encrypted bool) (TabletConn, error)

type TabletDialer

type TabletDialer func(addr, keyspace, shard, username, password string, encrypted bool) (TabletConn, error)

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

func GetDialer

func GetDialer(name string) TabletDialer

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 *rpcproto.Context, session *proto.Session, noOutput *string) error

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

func (*VTGate) CloseSession

func (vtg *VTGate) CloseSession(context *rpcproto.Context, session *proto.Session, noOutput *string) error

CloseSession closes the current session and releases all associated resources for the session.

func (*VTGate) Commit

func (vtg *VTGate) Commit(context *rpcproto.Context, session *proto.Session, noOutput *string) error

Commit commits a transaction.

func (*VTGate) ExecuteBatchShard

func (vtg *VTGate) ExecuteBatchShard(context *rpcproto.Context, batchQuery *proto.BatchQueryShard, reply *tproto.QueryResultList) error

ExecuteBatchShard executes a group of queries on the specified shards.

func (*VTGate) ExecuteShard

func (vtg *VTGate) ExecuteShard(context *rpcproto.Context, query *proto.QueryShard, reply *mproto.QueryResult) error

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

func (*VTGate) GetSessionId

func (vtg *VTGate) GetSessionId(sessionParams *proto.SessionParams, session *proto.Session) error

GetSessionId is the first request sent by the client to begin a session. The returned id should be used for all subsequent communications.

func (*VTGate) Rollback

func (vtg *VTGate) Rollback(context *rpcproto.Context, session *proto.Session, noOutput *string) error

Rollback rolls back a transaction.

func (*VTGate) StreamExecuteShard

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

StreamExecuteShard executes a streaming query on the specified shards.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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