connpool

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2021 License: Apache-2.0 Imports: 20 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 DBConn

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

DBConn 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 NewDBConn

func NewDBConn(ctx context.Context, cp *Pool, appParams dbconfigs.Connector) (*DBConn, error)

NewDBConn creates a new DBConn. It triggers a CheckMySQL if creation fails.

func NewDBConnNoPool

func NewDBConnNoPool(ctx context.Context, params dbconfigs.Connector, dbaPool *dbconnpool.ConnectionPool) (*DBConn, error)

NewDBConnNoPool creates a new DBConn without a pool.

func (*DBConn) BaseShowTables added in v0.10.0

func (dbc *DBConn) BaseShowTables() string

BaseShowTables returns a query that shows tables and their sizes

func (*DBConn) Close

func (dbc *DBConn) Close()

Close closes the DBConn.

func (*DBConn) Current

func (dbc *DBConn) Current() string

Current returns the currently executing query.

func (*DBConn) Err added in v0.9.0

func (dbc *DBConn) Err() error

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

func (*DBConn) Exec

func (dbc *DBConn) 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 (*DBConn) ExecOnce

func (dbc *DBConn) 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 (*DBConn) FetchNext added in v0.10.0

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

FetchNext returns the next result set.

func (*DBConn) ID

func (dbc *DBConn) ID() int64

ID returns the connection id.

func (*DBConn) IsClosed

func (dbc *DBConn) IsClosed() bool

IsClosed returns true if DBConn is closed.

func (*DBConn) Kill

func (dbc *DBConn) 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 (*DBConn) Recycle

func (dbc *DBConn) Recycle()

Recycle returns the DBConn to the pool.

func (*DBConn) Stream

func (dbc *DBConn) 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 (*DBConn) Taint

func (dbc *DBConn) Taint()

Taint unregister connection from original pool and taints the connection.

func (*DBConn) VerifyMode

func (dbc *DBConn) 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 {
	// 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) Active

func (cp *Pool) Active() int64

Active returns the number of active connections in the pool

func (*Pool) Available

func (cp *Pool) Available() int64

Available returns the number of available connections in the pool

func (*Pool) Capacity

func (cp *Pool) Capacity() int64

Capacity returns the pool capacity.

func (*Pool) Close

func (cp *Pool) Close()

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

func (*Pool) Exhausted

func (cp *Pool) Exhausted() int64

Exhausted returns the number of times available went to zero for the pool.

func (*Pool) Get

func (cp *Pool) Get(ctx context.Context) (*DBConn, error)

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

func (*Pool) IdleClosed

func (cp *Pool) IdleClosed() int64

IdleClosed returns the number of closed connections for the pool.

func (*Pool) IdleTimeout

func (cp *Pool) IdleTimeout() time.Duration

IdleTimeout returns the idle timeout for the pool.

func (*Pool) InUse

func (cp *Pool) InUse() int64

InUse returns the number of in-use connections in the pool

func (*Pool) MaxCap

func (cp *Pool) MaxCap() int64

MaxCap returns the maximum size of the pool

func (*Pool) Open

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

Open must be called before starting to use the pool.

func (*Pool) Put

func (cp *Pool) Put(conn *DBConn)

Put puts a connection into the pool.

func (*Pool) SetCapacity

func (cp *Pool) SetCapacity(capacity int) (err error)

SetCapacity alters the size of the pool at runtime.

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.

func (*Pool) WaitCount

func (cp *Pool) WaitCount() int64

WaitCount returns how many clients are waiting for a connection

func (*Pool) WaitTime

func (cp *Pool) WaitTime() time.Duration

WaitTime return the pool WaitTime.

Jump to

Keyboard shortcuts

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