Documentation ¶
Index ¶
- Variables
- type Config
- type ConnPool
- func (pool *ConnPool[C]) Active() int64
- func (pool *ConnPool[C]) Available() int64
- func (pool *ConnPool[C]) Capacity() int64
- func (pool *ConnPool[C]) Close()
- func (pool *ConnPool[C]) CloseWithContext(ctx context.Context) error
- func (pool *ConnPool[C]) Get(ctx context.Context, setting *Setting) (*Pooled[C], error)
- func (pool *ConnPool[D]) IdleTimeout() time.Duration
- func (pool *ConnPool[C]) InUse() int64
- func (pool *ConnPool[C]) IsOpen() bool
- func (pool *ConnPool[C]) MaxCapacity() int64
- func (pool *ConnPool[C]) Open(connect Connector[C], refresh RefreshCheck) *ConnPool[C]
- func (pool *ConnPool[D]) RefreshInterval() time.Duration
- func (pool *ConnPool[C]) RegisterStats(stats *servenv.Exporter, name string)
- func (pool *ConnPool[C]) SetCapacity(ctx context.Context, newcap int64) error
- func (pool *ConnPool[C]) SetIdleTimeout(duration time.Duration)
- func (pool *ConnPool[C]) StatsJSON() map[string]any
- type Connection
- type Connector
- type Metrics
- func (m *Metrics) DiffSettingCount() int64
- func (m *Metrics) GetCount() int64
- func (m *Metrics) GetSettingCount() int64
- func (m *Metrics) IdleClosed() int64
- func (m *Metrics) MaxLifetimeClosed() int64
- func (m *Metrics) ResetSettingCount() int64
- func (m *Metrics) WaitCount() int64
- func (m *Metrics) WaitTime() time.Duration
- type Pooled
- type RefreshCheck
- type Setting
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTimeout is returned if a connection get times out. ErrTimeout = vterrors.New(vtrpcpb.Code_RESOURCE_EXHAUSTED, "connection pool timed out") // ErrCtxTimeout is returned if a ctx is already expired by the time the connection pool is used ErrCtxTimeout = vterrors.New(vtrpcpb.Code_DEADLINE_EXCEEDED, "connection pool context already expired") // ErrConnPoolClosed is returned when trying to get a connection from a closed conn pool ErrConnPoolClosed = vterrors.New(vtrpcpb.Code_INTERNAL, "connection pool is closed") // PoolCloseTimeout is how long to wait for all connections to be returned to the pool during close PoolCloseTimeout = 10 * time.Second )
Functions ¶
This section is empty.
Types ¶
type ConnPool ¶
type ConnPool[C Connection] struct { Metrics Metrics Name string // contains filtered or unexported fields }
ConnPool is a connection pool for generic connections
func NewPool ¶
func NewPool[C Connection](config *Config[C]) *ConnPool[C]
NewPool creates a new connection pool with the given Config. The pool must be ConnPool.Open before it can start giving out connections
func (*ConnPool[C]) Active ¶
Active returns the numer of connections that the pool has currently open.
func (*ConnPool[C]) Available ¶
Available returns the number of connections that the pool can immediately lend out to clients without blocking.
func (*ConnPool[C]) Capacity ¶
Capacity returns the maximum amount of connections that this pool can maintain open
func (*ConnPool[C]) Close ¶
func (pool *ConnPool[C]) Close()
Close shuts down the pool. No connections will be returned from ConnPool.Get after calling this, but calling ConnPool.Put is still allowed. This function will not return until all of the pool's connections have been returned or the default PoolCloseTimeout has elapsed
func (*ConnPool[C]) CloseWithContext ¶
CloseWithContext behaves like Close but allows passing in a Context to time out the pool closing operation
func (*ConnPool[C]) Get ¶
Get returns a connection from the pool with the given Setting applied. If there are no connections in the pool to be returned, Get blocks until one is returned, or until the given ctx is cancelled. The connection must be returned to the pool once it's not needed by calling Pooled.Recycle
func (*ConnPool[D]) IdleTimeout ¶
func (*ConnPool[C]) InUse ¶
InUse returns the number of connections that the pool has lent out to clients and that haven't been returned yet.
func (*ConnPool[C]) MaxCapacity ¶
MaxCapacity returns the maximum value to which Capacity can be set via ConnPool.SetCapacity
func (*ConnPool[C]) Open ¶
func (pool *ConnPool[C]) Open(connect Connector[C], refresh RefreshCheck) *ConnPool[C]
Open starts the background workers that manage the pool and gets it ready to start serving out connections.
func (*ConnPool[D]) RefreshInterval ¶
func (*ConnPool[C]) RegisterStats ¶
RegisterStats registers this pool's metrics into a stats Exporter
func (*ConnPool[C]) SetCapacity ¶
SetCapacity changes the capacity (number of open connections) on the pool. If the capacity is smaller than the number of connections that there are currently open, we'll close enough connections before returning, even if that means waiting for clients to return connections to the pool. If the given context times out before we've managed to close enough connections an error will be returned.
func (*ConnPool[C]) SetIdleTimeout ¶
type Connection ¶
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
func (*Metrics) DiffSettingCount ¶
func (*Metrics) GetSettingCount ¶
func (*Metrics) IdleClosed ¶
func (*Metrics) MaxLifetimeClosed ¶
func (*Metrics) ResetSettingCount ¶
type Pooled ¶
type Pooled[C Connection] struct { Conn C // contains filtered or unexported fields }
type RefreshCheck ¶
type Setting ¶
type Setting struct {
// contains filtered or unexported fields
}
Setting is a setting applied to a connection in this pool. Setting values must be interned for optimal usage (i.e. a Setting that represents a specific set of SQL connection settings should always have the same pointer value).