dbconnpool

package
v2.0.0-beta.1+incompat... Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2016 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnPoolClosed is returned / panicked whent he
	// connection pool is closed.
	ErrConnPoolClosed = errors.New("connection pool is closed")
)

Functions

This section is empty.

Types

type ConnectionPool

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

ConnectionPool re-exposes ResourcePool as a pool of PoolConnection objects

func NewConnectionPool

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

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

func (*ConnectionPool) Available

func (cp *ConnectionPool) Available() int64

Available returns the number of available connections in the pool

func (*ConnectionPool) Capacity

func (cp *ConnectionPool) Capacity() int64

Capacity returns the pool capacity.

func (*ConnectionPool) Close

func (cp *ConnectionPool) Close()

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

func (*ConnectionPool) Get

func (cp *ConnectionPool) Get(timeout time.Duration) (PoolConnection, error)

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

func (*ConnectionPool) IdleTimeout

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

IdleTimeout returns the idle timeout for the pool.

func (*ConnectionPool) MaxCap

func (cp *ConnectionPool) MaxCap() int64

MaxCap returns the maximum size of the pool

func (*ConnectionPool) Open

func (cp *ConnectionPool) Open(connFactory CreateConnectionFunc)

Open must be call before starting to use the pool.

func (*ConnectionPool) Put

func (cp *ConnectionPool) Put(conn PoolConnection)

Put puts a connection into the pool.

func (*ConnectionPool) SetCapacity

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

SetCapacity alters the size of the pool at runtime.

func (*ConnectionPool) SetIdleTimeout

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

SetIdleTimeout sets the idleTimeout on the pool.

func (*ConnectionPool) StatsJSON

func (cp *ConnectionPool) StatsJSON() string

StatsJSON returns the pool stats as a JSOn object.

func (*ConnectionPool) WaitCount

func (cp *ConnectionPool) WaitCount() int64

WaitCount returns how many clients are waiting for a connection

func (*ConnectionPool) WaitTime

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

WaitTime return the pool WaitTime.

type CreateConnectionFunc

type CreateConnectionFunc func(*ConnectionPool) (connection PoolConnection, err error)

CreateConnectionFunc is the factory method to create new connections within the passed ConnectionPool.

func DBConnectionCreator

func DBConnectionCreator(info *sqldb.ConnParams, mysqlStats *stats.Timings) CreateConnectionFunc

DBConnectionCreator is the wrapper function to use to create a pool of DBConnection objects.

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

type DBConnection

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

DBConnection re-exposes sqldb.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

func NewDBConnection(info *sqldb.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

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

ExecuteFetch is part of PoolConnection interface.

func (*DBConnection) ExecuteStreamFetch

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

ExecuteStreamFetch is part of PoolConnection interface.

func (*DBConnection) VerifyStrict

func (dbc *DBConnection) VerifyStrict() bool

VerifyStrict is a helper method to verify mysql is running with sql_mode = STRICT_TRANS_TABLES.

type PoolConnection

type PoolConnection interface {
	ExecuteFetch(query string, maxrows int, wantfields bool) (*sqltypes.Result, error)
	ExecuteStreamFetch(query string, callback func(*sqltypes.Result) error, streamBufferSize int) error
	ID() int64
	Close()
	IsClosed() bool
	Recycle()
	Reconnect() error
}

PoolConnection is the interface implemented by users of this specialized pool.

type PooledDBConnection

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

PooledDBConnection re-exposes DBConnection as a PoolConnection

func (*PooledDBConnection) Reconnect

func (pc *PooledDBConnection) Reconnect() error

Reconnect replaces the existing underlying connection with a new one.

func (*PooledDBConnection) Recycle

func (pc *PooledDBConnection) Recycle()

Recycle implements PoolConnection's Recycle

Jump to

Keyboard shortcuts

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