connpool

package
v0.15.10 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

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

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

ApplySetting implements the pools.Resource interface.

func (*Conn) BaseShowTables

func (dbc *Conn) BaseShowTables() string

BaseShowTables returns a query that shows tables

func (*Conn) BaseShowTablesWithSizes

func (dbc *Conn) BaseShowTablesWithSizes() string

BaseShowTablesWithSizes returns a query that shows tables and their sizes

func (*Conn) Close

func (dbc *Conn) Close()

Close closes the DBConn.

func (*Conn) ConnCheck

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

func (*Conn) Current

func (dbc *Conn) Current() string

Current returns the currently executing query.

func (*Conn) CurrentForLogging

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

func (dbc *Conn) Err() error

Err returns an error if there was a client initiated error like a query kill and resets the error message on the connection.

func (*Conn) Exec

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

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

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

FetchNext returns the next result set.

func (*Conn) ID

func (dbc *Conn) ID() int64

ID returns the connection id.

func (*Conn) IsClosed

func (dbc *Conn) IsClosed() bool

IsClosed returns true if DBConn is closed.

func (*Conn) Kill

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

Kill executes a kill statement to terminate the connection.

func (*Conn) KillQuery

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

KillQuery executes a kill query statement to terminate the running query on the connection.

func (*Conn) Reconnect

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

func (*Conn) ResetSetting

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

ResetSetting implements the pools.Resource interface.

func (*Conn) Setting

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

func (*Conn) Stream

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

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

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

type PooledConn = smartconnpool.Pooled[*Conn]

Jump to

Keyboard shortcuts

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