server

package
v0.0.0-...-59b3a1c Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusUnset byte = 0
	StatusIdle  byte = 'I'
	StatusInTx  byte = 'T'
	StatusError byte = 'E'
)

Variables

View Source
var (
	ErrPoolClosed  = errors.New("pool is closed")
	ErrConnExpired = errors.New("connection expired")
)
View Source
var ErrCancelComplete = errors.New("cancel complete")

ErrCancelComplete is a special error to indicate the caller not to log any error messages, since on cancelRequest, the server just closes the connection.

Functions

This section is empty.

Types

type AuthRow

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

type ClientConn

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

func NewClientConn

func NewClientConn(handle *pgproto3.Backend, logger *log.Logger, pool *Pool, schema string) *ClientConn

func (*ClientConn) CancelServerConn

func (cc *ClientConn) CancelServerConn() error

type Conner

type Conner interface {
	Conn() net.Conn
	CheckConn() error
	Close(ctx context.Context) error
	Exec(ctx context.Context, sql string) *pgconn.MultiResultReader
	CancelRequest(ctx context.Context) error
}

type DBStats

type DBStats struct {
	MaxOpenConnections int // Maximum number of open connections to the database.

	// Pool Status
	OpenConnections int // The number of established connections both in use and idle.
	InUse           int // The number of connections currently in use.
	Idle            int // The number of idle connections.

	// Counters
	WaitCount         int64         // The total number of connections waited for.
	WaitDuration      time.Duration // The total time blocked waiting for a new connection.
	MaxIdleClosed     int64         // The total number of connections closed due to SetMaxIdleConns.
	MaxIdleTimeClosed int64         // The total number of connections closed due to SetConnMaxIdleTime.
	MaxLifetimeClosed int64         // The total number of connections closed due to SetConnMaxLifetime.
}

DBStats contains database statistics.

type Pool

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

Pool is a copied implementation of just the connection pooling logic from database/sql.

func NewPool

func NewPool(cfg PoolConfig) (*Pool, error)

func (*Pool) AcquireConn

func (p *Pool) AcquireConn() (*ServerConn, error)

func (*Pool) Close

func (p *Pool) Close() error

func (*Pool) ReleaseConn

func (p *Pool) ReleaseConn(sc *ServerConn)

putConn adds a connection to the db's free pool.

func (*Pool) Reload

func (p *Pool) Reload(new PoolConfig)

func (*Pool) SetConnMaxIdleTime

func (p *Pool) SetConnMaxIdleTime(d time.Duration)

SetConnMaxIdleTime sets the maximum amount of time a connection may be idle.

Expired connections may be closed lazily before reuse.

If d <= 0, connections are not closed due to a connection's idle time.

func (*Pool) SetConnMaxLifetime

func (p *Pool) SetConnMaxLifetime(d time.Duration)

SetConnMaxLifetime sets the maximum amount of time a connection may be reused.

Expired connections may be closed lazily before reuse.

If d <= 0, connections are not closed due to a connection's age.

func (*Pool) SetMaxIdleConns

func (p *Pool) SetMaxIdleConns(n int)

SetMaxIdleConns sets the maximum number of connections in the idle connection pool.

If MaxOpenConns is greater than 0 but less than the new MaxIdleConns, then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.

If n <= 0, no idle connections are retained.

The default max idle connections is currently 2. This may change in a future release.

func (*Pool) SetMaxOpenConns

func (p *Pool) SetMaxOpenConns(n int)

SetMaxOpenConns sets the maximum number of open connections to the database.

If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit.

If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).

func (*Pool) Stats

func (p *Pool) Stats() DBStats

Stats returns database statistics.

type PoolConfig

type PoolConfig struct {
	SpawnConn func(ctx context.Context) (Conner, error)
	Logger    *log.Logger

	MaxIdle           int
	MaxOpen           int
	MaxLifetime       time.Duration
	MaxIdleTime       time.Duration
	ConnCreateTimeout time.Duration
	ConnCloseTimeout  time.Duration
	SchemaExecTimeout time.Duration
}

type PoolManager

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

func NewPoolManager

func NewPoolManager(cfg config.Config, logger *log.Logger) (*PoolManager, error)

func (*PoolManager) Close

func (pm *PoolManager) Close() error

Close closes all pools

func (*PoolManager) GetOrCreatePool

func (pm *PoolManager) GetOrCreatePool(row AuthRow) (pool *Pool, err error)

func (*PoolManager) Reload

func (pm *PoolManager) Reload(cfg config.Config)

type Server

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

Server contains all the necessary information to run Perseus

func New

func New(cfg config.Config) (*Server, error)

New creates a new Perseus server

func (*Server) AcceptConns

func (s *Server) AcceptConns() error

func (*Server) Reload

func (s *Server) Reload(cfg config.Config)

func (*Server) Stop

func (s *Server) Stop()

Stop stops the server

type ServerConn

type ServerConn struct {
	sync.Mutex // guards following
	// contains filtered or unexported fields
}

func (*ServerConn) CancelRequest

func (sc *ServerConn) CancelRequest(ctx context.Context) error

func (*ServerConn) CheckConn

func (sc *ServerConn) CheckConn() error

func (*ServerConn) Close

func (sc *ServerConn) Close() error

func (*ServerConn) Conn

func (sc *ServerConn) Conn() net.Conn

func (*ServerConn) Exec

func (sc *ServerConn) Exec(sql string) error

Jump to

Keyboard shortcuts

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