Documentation ¶
Index ¶
- Variables
- type Config
- type Credentials
- type DB
- type StaticAuthCredentials
- type VTGateProxy
- func (vtgate *VTGateProxy) Close() error
- func (vtgate *VTGateProxy) Dial(ctx context.Context, target string, opts ...grpc.DialOption) error
- func (vtgate *VTGateProxy) Hostname() string
- func (vtgate *VTGateProxy) Ping() error
- func (vtgate *VTGateProxy) PingContext(ctx context.Context) error
- func (vtgate *VTGateProxy) ShowTablets(ctx context.Context) (*sql.Rows, error)
Constants ¶
This section is empty.
Variables ¶
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.
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 // Hostname returns the hostname the DB is currently connected to. Hostname() string // 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) 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) Hostname ¶
func (vtgate *VTGateProxy) Hostname() string
Hostname is part of the DB interface.
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 ¶
ShowTablets is part of the DB interface.