pool

package
v11.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func PutReaderContext

func PutReaderContext(rd *ReaderContext)

func PutWriteBuffer

func PutWriteBuffer(wb *WriteBuffer)

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 BufReader

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

func NewBufReader

func NewBufReader(bufSize int) *BufReader

func (*BufReader) Available

func (b *BufReader) Available() int

func (*BufReader) Buffered

func (b *BufReader) Buffered() int

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

func (*BufReader) Bytes

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

func (*BufReader) BytesReader

func (b *BufReader) BytesReader(n int) *BytesReader

func (*BufReader) Discard

func (b *BufReader) Discard(n int) (discarded int, err error)

Discard skips the next n bytes, returning the number of bytes discarded.

If Discard skips fewer than n bytes, it also returns an error. If 0 <= n <= b.Buffered(), Discard is guaranteed to succeed without reading from the underlying io.BufReader.

func (*BufReader) Read

func (b *BufReader) Read(p []byte) (n int, err error)

func (*BufReader) ReadByte

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

func (*BufReader) ReadBytes

func (b *BufReader) ReadBytes(fn func(byte) bool) (line []byte, err error)

func (*BufReader) ReadFull

func (b *BufReader) ReadFull() ([]byte, error)

func (*BufReader) ReadFullTemp

func (b *BufReader) ReadFullTemp() ([]byte, error)

func (*BufReader) ReadN

func (b *BufReader) ReadN(n int) (line []byte, err error)

func (*BufReader) ReadSlice

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

ReadSlice reads until the first occurrence of delim in the input, returning a slice pointing at the bytes in the buffer. The bytes stop being valid at the next read. If ReadSlice encounters an error before finding a delimiter, it returns all the data in the buffer and the error itself (often io.EOF). ReadSlice fails with error ErrBufferFull if the buffer fills without a delim. Because the data returned from ReadSlice will be overwritten by the next I/O operation, most clients should use ReadBytes or ReadString instead. ReadSlice returns err != nil if and only if line does not end in delim.

func (*BufReader) Reset

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

func (*BufReader) SetAvailable

func (b *BufReader) SetAvailable(n int)

func (*BufReader) UnreadByte

func (b *BufReader) UnreadByte() error

type BytesReader

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

func NewBytesReader

func NewBytesReader(b []byte) *BytesReader

func (*BytesReader) Buffered

func (r *BytesReader) Buffered() int

func (*BytesReader) Bytes

func (r *BytesReader) Bytes() []byte

func (*BytesReader) Discard

func (r *BytesReader) Discard(n int) (int, error)

func (*BytesReader) Read

func (r *BytesReader) Read(b []byte) (n int, err error)

func (*BytesReader) ReadByte

func (r *BytesReader) ReadByte() (byte, error)

func (*BytesReader) ReadBytes

func (r *BytesReader) ReadBytes(fn func(byte) bool) ([]byte, error)

func (*BytesReader) ReadFull

func (r *BytesReader) ReadFull() ([]byte, error)

func (*BytesReader) ReadFullTemp

func (r *BytesReader) ReadFullTemp() ([]byte, error)

func (*BytesReader) ReadN

func (r *BytesReader) ReadN(n int) ([]byte, error)

func (*BytesReader) ReadSlice

func (r *BytesReader) ReadSlice(delim byte) ([]byte, error)

func (*BytesReader) Reset

func (r *BytesReader) Reset(b []byte)

func (*BytesReader) UnreadByte

func (r *BytesReader) UnreadByte() error

type ColumnAlloc

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

func NewColumnAlloc

func NewColumnAlloc() *ColumnAlloc

func (*ColumnAlloc) Columns

func (c *ColumnAlloc) Columns() []ColumnInfo

func (*ColumnAlloc) New

func (c *ColumnAlloc) New(index int16, name []byte) *ColumnInfo

func (*ColumnAlloc) Reset

func (c *ColumnAlloc) Reset()

type ColumnInfo

type ColumnInfo struct {
	Index    int16
	DataType int32
	Name     []byte
}

type Conn

type Conn struct {
	ProcessID int32
	SecretKey int32

	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) LockReader

func (cn *Conn) LockReader()

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

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

func (*Conn) WithWriter

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

func (*Conn) WriteBuffer

func (cn *Conn) WriteBuffer(ctx context.Context, timeout time.Duration, wb *WriteBuffer) 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

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

func (*ConnPool) Filter

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

func (*ConnPool) Get

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

Get returns existed 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(c context.Context) (*Conn, error)

func (*ConnPool) Put

func (p *ConnPool) Put(ctx context.Context, cn *Conn)

func (*ConnPool) ReapStaleConns

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

func (*ConnPool) Remove

func (p *ConnPool) Remove(ctx context.Context, cn *Conn, reason error)

func (*ConnPool) Stats

func (p *ConnPool) Stats() Stats

type Options

type Options struct {
	Dialer  func(context.Context) (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(context.Context) (*Conn, error)
	CloseConn(*Conn) error

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

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

	Close() error
}

type Reader

type Reader interface {
	Buffered() int

	Bytes() []byte
	Read([]byte) (int, error)
	ReadByte() (byte, error)
	UnreadByte() error
	ReadSlice(byte) ([]byte, error)
	Discard(int) (int, error)

	// ReadBytes(fn func(byte) bool) ([]byte, error)
	// ReadN(int) ([]byte, error)
	ReadFull() ([]byte, error)
	ReadFullTemp() ([]byte, error)
}

type ReaderContext

type ReaderContext struct {
	*BufReader
	ColumnAlloc *ColumnAlloc
}

func GetReaderContext

func GetReaderContext() *ReaderContext

func NewReaderContext

func NewReaderContext() *ReaderContext

type SingleConnPool

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

func NewSingleConnPool

func NewSingleConnPool(pool Pooler, cn *Conn) *SingleConnPool

func (*SingleConnPool) Close

func (p *SingleConnPool) Close() error

func (*SingleConnPool) CloseConn

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

func (*SingleConnPool) Get

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

func (*SingleConnPool) IdleLen

func (p *SingleConnPool) IdleLen() int

func (*SingleConnPool) Len

func (p *SingleConnPool) Len() int

func (*SingleConnPool) NewConn

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

func (*SingleConnPool) Put

func (p *SingleConnPool) Put(ctx context.Context, cn *Conn)

func (*SingleConnPool) Remove

func (p *SingleConnPool) Remove(ctx context.Context, cn *Conn, reason error)

func (*SingleConnPool) Stats

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 StickyConnPool

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

func NewStickyConnPool

func NewStickyConnPool(pool Pooler) *StickyConnPool

func (*StickyConnPool) Close

func (p *StickyConnPool) Close() error

func (*StickyConnPool) CloseConn

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

func (*StickyConnPool) Get

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

func (*StickyConnPool) IdleLen

func (p *StickyConnPool) IdleLen() int

func (*StickyConnPool) Len

func (p *StickyConnPool) Len() int

func (*StickyConnPool) NewConn

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

func (*StickyConnPool) Put

func (p *StickyConnPool) Put(ctx context.Context, cn *Conn)

func (*StickyConnPool) Remove

func (p *StickyConnPool) Remove(ctx context.Context, cn *Conn, reason error)

func (*StickyConnPool) Reset

func (p *StickyConnPool) Reset(ctx context.Context) error

func (*StickyConnPool) Stats

func (p *StickyConnPool) Stats() Stats

type WriteBuffer

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

func GetWriteBuffer

func GetWriteBuffer() *WriteBuffer

func NewWriteBuffer

func NewWriteBuffer() *WriteBuffer

func (*WriteBuffer) FinishMessage

func (buf *WriteBuffer) FinishMessage()

func (*WriteBuffer) FinishNullParam

func (buf *WriteBuffer) FinishNullParam()

func (*WriteBuffer) FinishParam

func (buf *WriteBuffer) FinishParam()

func (*WriteBuffer) Query

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

func (*WriteBuffer) ReadFrom

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

func (*WriteBuffer) Reset

func (buf *WriteBuffer) Reset()

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