pool

package
v6.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Conn

type Conn struct {
	InitedAt time.Time

	ProcessId int32
	SecretKey int32
	// contains filtered or unexported fields
}

func NewConn

func NewConn(netConn net.Conn) *Conn

func (*Conn) Close

func (cn *Conn) Close() error

func (*Conn) LockReaderBuffer added in v6.14.4

func (cn *Conn) LockReaderBuffer()

func (*Conn) NetConn

func (cn *Conn) NetConn() net.Conn

func (*Conn) NextId

func (cn *Conn) NextId() string

func (*Conn) RemoteAddr

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

func (*Conn) SetNetConn

func (cn *Conn) SetNetConn(netConn net.Conn)

func (*Conn) SetUsedAt added in v6.13.6

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

func (*Conn) UsedAt

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

func (*Conn) WithReader added in v6.14.4

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

func (*Conn) WithWriter added in v6.14.4

func (cn *Conn) WithWriter(timeout time.Duration, fn func(wb *WriteBuffer) error) error

type ConnPool

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

func NewConnPool

func NewConnPool(opt *Options) *ConnPool

func (*ConnPool) Close

func (p *ConnPool) Close() error

func (*ConnPool) CloseConn added in v6.1.0

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

func (*ConnPool) Filter added in v6.14.4

func (p *ConnPool) Filter(fn func(*Conn) bool) error

func (*ConnPool) Get

func (p *ConnPool) Get() (*Conn, error)

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

func (*ConnPool) IdleLen added in v6.13.6

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() (*Conn, error)

func (*ConnPool) Put

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

func (*ConnPool) ReapStaleConns

func (p *ConnPool) ReapStaleConns() (int, error)

func (*ConnPool) Remove

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

func (*ConnPool) Stats

func (p *ConnPool) Stats() *Stats

type ElasticBufReader added in v6.14.4

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

ElasticBufReader is like bufio.Reader but instead of returning ErrBufferFull it automatically grows the buffer.

func NewElasticBufReader added in v6.14.4

func NewElasticBufReader(rd io.Reader) *ElasticBufReader

func (*ElasticBufReader) Buffer added in v6.14.4

func (b *ElasticBufReader) Buffer() []byte

func (*ElasticBufReader) Buffered added in v6.14.4

func (b *ElasticBufReader) Buffered() int

Buffered returns the number of bytes that can be read from the current buffer.

func (*ElasticBufReader) Bytes added in v6.14.4

func (b *ElasticBufReader) Bytes() []byte

func (*ElasticBufReader) ReadByte added in v6.14.4

func (b *ElasticBufReader) ReadByte() (byte, error)

func (*ElasticBufReader) ReadLine added in v6.14.4

func (b *ElasticBufReader) ReadLine() (line []byte, err error)

func (*ElasticBufReader) ReadN added in v6.14.4

func (b *ElasticBufReader) ReadN(n int) ([]byte, error)

func (*ElasticBufReader) ReadSlice added in v6.14.4

func (b *ElasticBufReader) ReadSlice(delim byte) (line []byte, err error)

func (*ElasticBufReader) Reset added in v6.14.4

func (b *ElasticBufReader) Reset(rd io.Reader)

func (*ElasticBufReader) ResetBuffer added in v6.14.4

func (b *ElasticBufReader) ResetBuffer(buf []byte)

type Options

type Options struct {
	Dialer  func() (net.Conn, error)
	OnClose func(*Conn) error

	PoolSize           int
	MinIdleConns       int
	MaxConnAge         time.Duration
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration
}

type Pooler

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

	Get() (*Conn, error)
	Put(*Conn)
	Remove(*Conn)

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

	Close() error
}

type Reader added in v6.14.4

type Reader struct {
	*ElasticBufReader
	Columns [][]byte
}

func NewReader added in v6.14.4

func NewReader(buf *ElasticBufReader) *Reader

func (*Reader) ReadError added in v6.14.4

func (rd *Reader) ReadError() (error, error)

func (*Reader) ReadInt16 added in v6.14.4

func (rd *Reader) ReadInt16() (int16, error)

func (*Reader) ReadInt32 added in v6.14.4

func (rd *Reader) ReadInt32() (int32, error)

func (*Reader) ReadMessageType added in v6.14.4

func (rd *Reader) ReadMessageType() (byte, int, error)

func (*Reader) ReadString added in v6.14.4

func (rd *Reader) ReadString() (string, error)

type SingleConnPool added in v6.4.22

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

func NewSingleConnPool added in v6.4.22

func NewSingleConnPool(cn *Conn) *SingleConnPool

func (*SingleConnPool) Close added in v6.4.22

func (p *SingleConnPool) Close() error

func (*SingleConnPool) CloseConn added in v6.4.22

func (p *SingleConnPool) CloseConn(*Conn) error

func (*SingleConnPool) Get added in v6.4.22

func (p *SingleConnPool) Get() (*Conn, error)

func (*SingleConnPool) IdleLen added in v6.13.6

func (p *SingleConnPool) IdleLen() int

func (*SingleConnPool) Len added in v6.4.22

func (p *SingleConnPool) Len() int

func (*SingleConnPool) NewConn added in v6.4.22

func (p *SingleConnPool) NewConn() (*Conn, error)

func (*SingleConnPool) Put added in v6.4.22

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

func (*SingleConnPool) Remove added in v6.4.22

func (p *SingleConnPool) Remove(cn *Conn)

func (*SingleConnPool) Stats added in v6.4.22

func (p *SingleConnPool) Stats() *Stats

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.

type WriteBuffer

type WriteBuffer struct {
	Bytes []byte
	// contains filtered or unexported fields
}

func NewWriteBuffer

func NewWriteBuffer() *WriteBuffer

func (*WriteBuffer) Buffer added in v6.14.4

func (buf *WriteBuffer) Buffer() []byte

func (*WriteBuffer) FinishMessage

func (buf *WriteBuffer) FinishMessage()

func (*WriteBuffer) FinishNullParam

func (buf *WriteBuffer) FinishNullParam()

func (*WriteBuffer) FinishParam

func (buf *WriteBuffer) FinishParam()

func (*WriteBuffer) ReadFrom

func (buf *WriteBuffer) ReadFrom(r io.Reader) (int64, error)

func (*WriteBuffer) Reset

func (buf *WriteBuffer) Reset()

func (*WriteBuffer) ResetBuffer added in v6.14.4

func (buf *WriteBuffer) ResetBuffer(b []byte)

func (*WriteBuffer) StartMessage

func (buf *WriteBuffer) StartMessage(c byte)

func (*WriteBuffer) StartParam

func (buf *WriteBuffer) StartParam()

func (*WriteBuffer) Write

func (buf *WriteBuffer) Write(b []byte) (int, error)

func (*WriteBuffer) WriteByte

func (buf *WriteBuffer) WriteByte(c byte) error

func (*WriteBuffer) WriteBytes

func (buf *WriteBuffer) WriteBytes(b []byte)

func (*WriteBuffer) WriteInt16

func (buf *WriteBuffer) WriteInt16(num int16)

func (*WriteBuffer) WriteInt32

func (buf *WriteBuffer) WriteInt32(num int32)

func (*WriteBuffer) WriteString

func (buf *WriteBuffer) WriteString(s string)

Jump to

Keyboard shortcuts

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