go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/dbconnpool Index | Files

package dbconnpool

import "gopkg.in/src-d/go-vitess.v1/vt/dbconnpool"

Package dbconnpool exposes a single DBConnection object with wrapped access to a single DB connection, and a ConnectionPool object to pool these DBConnections.

Index

Package Files

connection.go connection_pool.go pooled_connection.go

Variables

var (
    // ErrConnPoolClosed is returned if the connection pool is closed.
    ErrConnPoolClosed = errors.New("connection pool is closed")
)

type ConnectionPool Uses

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

ConnectionPool re-exposes ResourcePool as a pool of PooledDBConnection objects.

func NewConnectionPool Uses

func NewConnectionPool(name string, capacity int, idleTimeout time.Duration, dnsResolutionFrequency time.Duration) *ConnectionPool

NewConnectionPool creates a new ConnectionPool. The name is used to publish stats only.

func (*ConnectionPool) Active Uses

func (cp *ConnectionPool) Active() int64

Active returns the number of active connections in the pool

func (*ConnectionPool) Available Uses

func (cp *ConnectionPool) Available() int64

Available returns the number of available connections in the pool

func (*ConnectionPool) Capacity Uses

func (cp *ConnectionPool) Capacity() int64

Capacity returns the pool capacity.

func (*ConnectionPool) Close Uses

func (cp *ConnectionPool) Close()

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

func (*ConnectionPool) Get Uses

func (cp *ConnectionPool) Get(ctx context.Context) (*PooledDBConnection, error)

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

func (*ConnectionPool) IdleClosed Uses

func (cp *ConnectionPool) IdleClosed() int64

IdleClosed returns the number of closed connections for the pool.

func (*ConnectionPool) IdleTimeout Uses

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

IdleTimeout returns the idle timeout for the pool.

func (*ConnectionPool) InUse Uses

func (cp *ConnectionPool) InUse() int64

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

func (*ConnectionPool) MaxCap Uses

func (cp *ConnectionPool) MaxCap() int64

MaxCap returns the maximum size of the pool

func (*ConnectionPool) Open Uses

func (cp *ConnectionPool) Open(info *mysql.ConnParams, mysqlStats *stats.Timings)

Open must be call before starting to use the pool.

For instance: mysqlStats := stats.NewTimings("Mysql") pool := dbconnpool.NewConnectionPool("name", 10, 30*time.Second) pool.Open(info, mysqlStats) ... conn, err := pool.Get() ...

func (*ConnectionPool) Put Uses

func (cp *ConnectionPool) Put(conn *PooledDBConnection)

Put puts a connection into the pool.

func (*ConnectionPool) SetCapacity Uses

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

SetCapacity alters the size of the pool at runtime.

func (*ConnectionPool) SetIdleTimeout Uses

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

SetIdleTimeout sets the idleTimeout on the pool.

func (*ConnectionPool) StatsJSON Uses

func (cp *ConnectionPool) StatsJSON() string

StatsJSON returns the pool stats as a JSOn object.

func (*ConnectionPool) WaitCount Uses

func (cp *ConnectionPool) WaitCount() int64

WaitCount returns how many clients are waiting for a connection

func (*ConnectionPool) WaitTime Uses

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

WaitTime return the pool WaitTime.

type DBConnection Uses

type DBConnection struct {
    *mysql.Conn
    // contains filtered or unexported fields
}

DBConnection re-exposes mysql.Conn with some wrapping to implement most of PoolConnection interface, except Recycle. That way it can be used by itself. (Recycle needs to know about the Pool).

func NewDBConnection Uses

func NewDBConnection(info *mysql.ConnParams, mysqlStats *stats.Timings) (*DBConnection, error)

NewDBConnection returns a new DBConnection based on the ConnParams and will use the provided stats to collect timing.

func (*DBConnection) ExecuteFetch Uses

func (dbc *DBConnection) ExecuteFetch(query string, maxrows int, wantfields bool) (*sqltypes.Result, error)

ExecuteFetch overwrites mysql.Conn.ExecuteFetch.

func (*DBConnection) ExecuteStreamFetch Uses

func (dbc *DBConnection) ExecuteStreamFetch(query string, callback func(*sqltypes.Result) error, streamBufferSize int) error

ExecuteStreamFetch overwrites mysql.Conn.ExecuteStreamFetch.

type PooledDBConnection Uses

type PooledDBConnection struct {
    *DBConnection
    // contains filtered or unexported fields
}

PooledDBConnection re-exposes DBConnection to be used by ConnectionPool.

func (*PooledDBConnection) Reconnect Uses

func (pc *PooledDBConnection) Reconnect() error

Reconnect replaces the existing underlying connection with a new one, if possible. Recycle should still be called afterwards.

func (*PooledDBConnection) Recycle Uses

func (pc *PooledDBConnection) Recycle()

Recycle should be called to return the PooledDBConnection to the pool.

Package dbconnpool imports 12 packages (graph) and is imported by 8 packages. Updated 2019-06-17. Refresh now. Tools for package owners.