connpool

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 24 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConnPoolClosed = vterrors.New(vtrpcpb.Code_INTERNAL, "internal error: unexpected: conn pool is closed")

ErrConnPoolClosed is returned when the connection pool is closed.

Functions

This section is empty.

Types

type Conn added in v0.19.0

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

Conn is a db connection for tabletserver. It performs automatic reconnects as needed. Its Execute function has a timeout that can kill its own queries and the underlying connection. It will also trigger a CheckMySQL whenever applicable.

func NewConn added in v0.19.0

func NewConn(ctx context.Context, params dbconfigs.Connector, dbaPool *dbconnpool.ConnectionPool, setting *smartconnpool.Setting, env tabletenv.Env) (*Conn, error)

NewConn creates a new Conn without a pool.

func (*Conn) ApplySetting added in v0.19.0

func (dbc *Conn) ApplySetting(ctx context.Context, setting *smartconnpool.Setting) error

ApplySetting implements the pools.Resource interface.

func (*Conn) BaseShowTables added in v0.19.0

func (dbc *Conn) BaseShowTables() string

BaseShowTables returns a query that shows tables

func (*Conn) BaseShowTablesWithSizes added in v0.19.0

func (dbc *Conn) BaseShowTablesWithSizes() string

BaseShowTablesWithSizes returns a query that shows tables and their sizes

func (*Conn) Close added in v0.19.0

func (dbc *Conn) Close()

Close closes the DBConn.

func (*Conn) ConnCheck added in v0.19.0

func (dbc *Conn) ConnCheck(ctx context.Context) error

func (*Conn) Current added in v0.19.0

func (dbc *Conn) Current() string

Current returns the currently executing query.

func (*Conn) CurrentForLogging added in v0.19.0

func (dbc *Conn) CurrentForLogging() string

CurrentForLogging applies transformations to the query making it suitable to log. It applies sanitization rules based on tablet settings and limits the max length of queries.

func (*Conn) Err added in v0.19.0

func (dbc *Conn) Err() error

Err returns an error if there was a client initiated error like a query kill.

func (*Conn) Exec added in v0.19.0

func (dbc *Conn) Exec(ctx context.Context, query string, maxrows int, wantfields bool) (*sqltypes.Result, error)

Exec executes the specified query. If there is a connection error, it will reconnect and retry. A failed reconnect will trigger a CheckMySQL.

func (*Conn) ExecOnce added in v0.19.0

func (dbc *Conn) ExecOnce(ctx context.Context, query string, maxrows int, wantfields bool) (*sqltypes.Result, error)

ExecOnce executes the specified query, but does not retry on connection errors.

func (*Conn) FetchNext added in v0.19.0

func (dbc *Conn) FetchNext(ctx context.Context, maxrows int, wantfields bool) (*sqltypes.Result, error)

FetchNext returns the next result set.

func (*Conn) ID added in v0.19.0

func (dbc *Conn) ID() int64

ID returns the connection id.

func (*Conn) IsClosed added in v0.19.0

func (dbc *Conn) IsClosed() bool

IsClosed returns true if DBConn is closed.

func (*Conn) Kill added in v0.19.0

func (dbc *Conn) Kill(reason string, elapsed time.Duration) error

Kill kills the currently executing query both on MySQL side and on the connection side. If no query is executing, it's a no-op. Kill will also not kill a query more than once.

func (*Conn) Reconnect added in v0.19.0

func (dbc *Conn) Reconnect(ctx context.Context) error

func (*Conn) ResetSetting added in v0.19.0

func (dbc *Conn) ResetSetting(ctx context.Context) error

ResetSetting implements the pools.Resource interface.

func (*Conn) Setting added in v0.19.0

func (dbc *Conn) Setting() *smartconnpool.Setting

func (*Conn) Stream added in v0.19.0

func (dbc *Conn) Stream(ctx context.Context, query string, callback func(*sqltypes.Result) error, alloc func() *sqltypes.Result, streamBufferSize int, includedFields querypb.ExecuteOptions_IncludedFields) error

Stream executes the query and streams the results.

func (*Conn) StreamOnce added in v0.19.0

func (dbc *Conn) StreamOnce(ctx context.Context, query string, callback func(*sqltypes.Result) error, alloc func() *sqltypes.Result, streamBufferSize int, includedFields querypb.ExecuteOptions_IncludedFields) error

StreamOnce executes the query and streams the results. But, does not retry on connection errors.

func (*Conn) VerifyMode added in v0.19.0

func (dbc *Conn) VerifyMode(strictTransTables bool) error

VerifyMode is a helper method to verify mysql is running with sql_mode = STRICT_TRANS_TABLES or STRICT_ALL_TABLES and autocommit=ON.

type Pool

type Pool struct {
	*smartconnpool.ConnPool[*Conn]
	// contains filtered or unexported fields
}

Pool implements a custom connection pool for tabletserver. It's similar to dbconnpool.ConnPool, but the connections it creates come with built-in ability to kill in-flight queries. These connections also trigger a CheckMySQL call if we fail to connect to MySQL. Other than the connection type, ConnPool maintains an additional pool of dba connections that are used to kill connections.

func NewPool

func NewPool(env tabletenv.Env, name string, cfg tabletenv.ConnPoolConfig) *Pool

NewPool creates a new Pool. The name is used to publish stats only.

func (*Pool) Close

func (cp *Pool) Close()

Close will close the pool and wait for connections to be returned before exiting.

func (*Pool) Get

func (cp *Pool) Get(ctx context.Context, setting *smartconnpool.Setting) (*PooledConn, error)

Get returns a connection. You must call Recycle on DBConn once done.

func (*Pool) Open

func (cp *Pool) Open(appParams, dbaParams, appDebugParams dbconfigs.Connector)

Open must be called before starting to use the pool.

func (*Pool) SetIdleTimeout

func (cp *Pool) SetIdleTimeout(idleTimeout time.Duration)

SetIdleTimeout sets the idleTimeout on the pool.

func (*Pool) StatsJSON

func (cp *Pool) StatsJSON() string

StatsJSON returns the pool stats as a JSON object.

type PooledConn added in v0.19.0

type PooledConn = smartconnpool.Pooled[*Conn]

Jump to

Keyboard shortcuts

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