vtsql

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConnClosed = errors.New("use of closed connection")

ErrConnClosed is returned when attempting to use a closed connection.

Functions

This section is empty.

Types

type Config

type Config struct {
	Discovery     discovery.Discovery
	DiscoveryTags []string
	Credentials   Credentials

	DialPingTimeout time.Duration

	// CredentialsPath is used only to power vtadmin debug endpoints; there may
	// be a better way where we don't need to put this in the config, because
	// it's not really an "option" in normal use.
	CredentialsPath string

	Cluster *vtadminpb.Cluster
}

Config represents the options that modify the behavior of a vtqsl.VTGateProxy.

func Parse

func Parse(cluster *vtadminpb.Cluster, disco discovery.Discovery, args []string) (*Config, error)

Parse returns a new config with the given cluster ID and name, after attempting to parse the command-line pflags into that Config. See (*Config).Parse() for more details.

func (*Config) Parse

func (c *Config) Parse(args []string) error

Parse reads options specified as command-line pflags (--key=value, note the double-dash!) into a vtsql.Config. It is meant to be called from (*cluster.Cluster).New().

type Credentials

type Credentials interface {
	// GetEffectiveUsername returns the username on whose behalf the DB is
	// issuing queries.
	GetEffectiveUsername() string
	// GetUsername returns the immediate username for a DB connection.
	GetUsername() string
	credentials.PerRPCCredentials
}

Credentials defines the interface needed for vtsql properly connect to and query Vitess databases.

type DB

type DB interface {
	// ShowTablets executes `SHOW vitess_tablets` and returns the result.
	ShowTablets(ctx context.Context) (*sql.Rows, error)

	// Dial opens a gRPC database connection to a vtgate in the cluster. If the
	// DB already has a valid connection, this is a no-op.
	//
	// target is a Vitess query target, e.g. "", "<keyspace>", "<keyspace>@replica".
	Dial(ctx context.Context, target string, opts ...grpc.DialOption) error

	// Ping behaves like (*sql.DB).Ping.
	Ping() error
	// PingContext behaves like (*sql.DB).PingContext.
	PingContext(ctx context.Context) error

	// Close closes the currently-held database connection. This is a no-op if
	// the DB has no current valid connection. It is safe to call repeatedly.
	// Users may call Dial on a previously-closed DB to create a new connection,
	// but that connection may not be to the same particular vtgate.
	Close() error
}

DB defines the connection and query interface of vitess SQL queries used by VTAdmin clusters.

type StaticAuthCredentials

type StaticAuthCredentials struct {
	*grpcclient.StaticAuthClientCreds
	EffectiveUser string
}

StaticAuthCredentials augments a grpcclient.StaticAuthClientCreds with an effective username.

func (*StaticAuthCredentials) GetEffectiveUsername

func (creds *StaticAuthCredentials) GetEffectiveUsername() string

GetEffectiveUsername is part of the Credentials interface.

func (*StaticAuthCredentials) GetUsername

func (creds *StaticAuthCredentials) GetUsername() string

GetUsername is part of the Credentials interface.

type VTGateProxy

type VTGateProxy struct {

	// DialFunc is called to open a new database connection. In production this
	// should always be vitessdriver.OpenWithConfiguration, but it is exported
	// for testing purposes.
	DialFunc func(cfg vitessdriver.Configuration) (*sql.DB, error)
	// contains filtered or unexported fields
}

VTGateProxy is a proxy for creating and using database connections to vtgates in a Vitess cluster.

func New

func New(cfg *Config) *VTGateProxy

New returns a VTGateProxy to the given cluster. When Dial-ing, it will use the given discovery implementation to find a vtgate to connect to, and the given creds to dial the underlying gRPC connection, both of which are provided by the Config.

It does not open a connection to a vtgate; users must call Dial before first use.

func (*VTGateProxy) Close

func (vtgate *VTGateProxy) Close() error

Close is part of the DB interface and satisfies io.Closer.

func (*VTGateProxy) Debug added in v0.12.0

func (vtgate *VTGateProxy) Debug() map[string]interface{}

Debug implements debug.Debuggable for VTGateProxy.

func (*VTGateProxy) Dial

func (vtgate *VTGateProxy) Dial(ctx context.Context, target string, opts ...grpc.DialOption) error

Dial is part of the DB interface. The proxy's DiscoveryTags can be set to narrow the set of possible gates it will connect to.

func (*VTGateProxy) Ping

func (vtgate *VTGateProxy) Ping() error

Ping is part of the DB interface.

func (*VTGateProxy) PingContext

func (vtgate *VTGateProxy) PingContext(ctx context.Context) error

PingContext is part of the DB interface.

func (*VTGateProxy) ShowTablets

func (vtgate *VTGateProxy) ShowTablets(ctx context.Context) (*sql.Rows, error)

ShowTablets is part of the DB interface.

Directories

Path Synopsis
Package fakevtsql provides an interface for mocking out sql.DB responses in tests that depend on a vtsql.DB instance.
Package fakevtsql provides an interface for mocking out sql.DB responses in tests that depend on a vtsql.DB instance.

Jump to

Keyboard shortcuts

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