chpool

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: BSD-2-Clause Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed      = errors.New("ch: database is closed")
	ErrPoolTimeout = errors.New("ch: connection pool timeout")
)

Functions

This section is empty.

Types

type BadConnError

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

func (BadConnError) Error

func (e BadConnError) Error() string

func (BadConnError) Unwrap

func (e BadConnError) Unwrap() error

type Config

type Config struct {
	Dialer  func(context.Context) (net.Conn, error)
	OnClose func(*Conn) error

	PoolSize        int
	PoolTimeout     time.Duration
	MaxIdleConns    int
	ConnMaxIdleTime time.Duration
	ConnMaxLifetime time.Duration
}

type Conn

type Conn struct {
	ServerInfo chproto.ServerInfo

	Inited bool
	// contains filtered or unexported fields
}

func NewConn

func NewConn(netConn net.Conn) *Conn

func (*Conn) Close

func (cn *Conn) Close() error

func (*Conn) Closed

func (cn *Conn) Closed() bool

func (*Conn) LocalAddr added in v0.2.8

func (cn *Conn) LocalAddr() net.Addr

func (*Conn) Reader added in v0.2.6

func (cn *Conn) Reader(ctx context.Context, timeout time.Duration) *chproto.Reader

func (*Conn) RemoteAddr

func (cn *Conn) RemoteAddr() net.Addr

func (*Conn) SetUsedAt

func (cn *Conn) SetUsedAt(tm time.Time)

func (*Conn) UsedAt

func (cn *Conn) UsedAt() time.Time

func (*Conn) WithReader

func (cn *Conn) WithReader(
	ctx context.Context,
	timeout time.Duration,
	fn func(rd *chproto.Reader) error,
) error

func (*Conn) WithWriter

func (cn *Conn) WithWriter(
	ctx context.Context,
	timeout time.Duration,
	fn func(wb *chproto.Writer),
) error

type ConnPool

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

func New

func New(cfg *Config) *ConnPool

func (*ConnPool) Close

func (p *ConnPool) Close() error

func (*ConnPool) CloseConn

func (p *ConnPool) CloseConn(cn *Conn) error

func (*ConnPool) Get

func (p *ConnPool) Get(ctx context.Context) (*Conn, error)

Get returns an existing connection from the pool or creates a new one.

func (*ConnPool) IdleLen

func (p *ConnPool) IdleLen() int

IdleLen returns number of idle connections.

func (*ConnPool) Len

func (p *ConnPool) Len() int

Len returns total number of connections.

func (*ConnPool) NewConn

func (p *ConnPool) NewConn(ctx context.Context) (*Conn, error)

func (*ConnPool) Put

func (p *ConnPool) Put(cn *Conn)

func (*ConnPool) Remove

func (p *ConnPool) Remove(cn *Conn, reason error)

func (*ConnPool) Stats

func (p *ConnPool) Stats() *Stats

type Pooler

type Pooler interface {
	NewConn(context.Context) (*Conn, error)
	CloseConn(*Conn) error

	Get(context.Context) (*Conn, error)
	Put(*Conn)
	Remove(*Conn, error)

	Len() int
	IdleLen() int
	Stats() *Stats

	Close() error
}

type Stats

type Stats struct {
	Hits     uint32 // number of times free connection was found in the pool
	Misses   uint32 // number of times free connection was NOT found in the pool
	Timeouts uint32 // number of times a wait timeout occurred

	TotalConns uint32 // number of total connections in the pool
	IdleConns  uint32 // number of idle connections in the pool
	StaleConns uint32 // number of stale connections removed from the pool
}

Stats contains pool state information and accumulated stats.

Jump to

Keyboard shortcuts

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