Documentation ¶
Index ¶
- type Config
- type Conn
- type Pool
- type Stat
- func (s *Stat) AcquireCount() int64
- func (s *Stat) AcquireDuration() time.Duration
- func (s *Stat) AcquiredConns() int32
- func (s *Stat) CanceledAcquireCount() int64
- func (s *Stat) ConstructingConns() int32
- func (s *Stat) EmptyAcquireCount() int64
- func (s *Stat) IdleConns() int32
- func (s *Stat) MaxConns() int32
- func (s *Stat) MaxIdleDestroyCount() int64
- func (s *Stat) MaxLifetimeDestroyCount() int64
- func (s *Stat) NewConnsCount() int64
- func (s *Stat) TotalConns() int32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { ConnConfig *chconn.Config // BeforeConnect is called before a new connection is made. It is passed a copy of the underlying chconn.Config and // will not impact any existing open connections. BeforeConnect func(context.Context, *chconn.Config) error // AfterConnect is called after a connection is established, but before it is added to the pool. AfterConnect func(context.Context, chconn.Conn) error // BeforeAcquire is called before a connection is acquired from the pool. It must return true to allow the // acquision or false to indicate that the connection should be destroyed and a different connection should be // acquired. BeforeAcquire func(context.Context, chconn.Conn) bool // AfterRelease is called after a connection is released, but before it is returned to the pool. It must return true to // return the connection to the pool or false to destroy the connection. AfterRelease func(chconn.Conn) bool // MaxConnLifetime is the duration since creation after which a connection will be automatically closed. MaxConnLifetime time.Duration // MaxConnLifetimeJitter is the duration after MaxConnLifetime to randomly decide to close a connection. // This helps prevent all connections from being closed at the exact same time, starving the pool. MaxConnLifetimeJitter time.Duration // MaxConnIdleTime is the duration after which an idle connection will be automatically closed by the health check. MaxConnIdleTime time.Duration // MaxConns is the maximum size of the pool. The default is the greater of 4 or runtime.NumCPU(). MaxConns int32 // MinConns is the minimum size of the pool. After connection closes, the pool might dip below MinConns. A low // number of MinConns might mean the pool is empty after MaxConnLifetime until the health check has a chance // to create new connections. MinConns int32 // HealthCheckPeriod is the duration between checks of the health of idle connections. HealthCheckPeriod time.Duration // CreateIdleTimeout is the timeout for create idle connection CreateIdleTimeout time.Duration // contains filtered or unexported fields }
Config is the configuration struct for creating a pool. It must be created by ParseConfig and then it can be modified. A manually initialized Config will cause ConnectConfig to panic.
func ParseConfig ¶
ParseConfig builds a Config from connString. It parses connString with the same behavior as chconn.ParseConfig with the addition of the following variables:
pool_max_conns: integer greater than 0 pool_min_conns: integer 0 or greater pool_max_conn_lifetime: duration string pool_max_conn_idle_time: duration string pool_health_check_period: duration string pool_max_conn_lifetime_jitter: duration string pool_create_idle_timeout: duration string
See Config for definitions of these arguments.
# Example DSN user=vahid password=secret host=clickhouse.example.com port=9000 dbname=mydb sslmode=verify-ca pool_max_conns=10 # Example URL clickhouse://vahid:secret@ch.example.com:9000/mydb?sslmode=verify-ca&pool_max_conns=10
func (*Config) ConnString ¶
ConnString returns the connection string as parsed by pgxpool.ParseConfig into pgxpool.Config.
type Conn ¶
type Conn interface { Release() // ExecWithOption executes a query without returning any rows with Query options. // NOTE: don't use it for insert and select query ExecWithOption( ctx context.Context, query string, queryOptions *chconn.QueryOptions, ) error // Select executes a query with the the query options and return select stmt. // NOTE: only use for select query SelectWithOption( ctx context.Context, query string, queryOptions *chconn.QueryOptions, columns ...column.ColumnBasic, ) (chconn.SelectStmt, error) // InsertWithSetting executes a query with the query options and commit all columns data. // NOTE: only use for insert query InsertWithOption(ctx context.Context, query string, queryOptions *chconn.QueryOptions, columns ...column.ColumnBasic) error // InsertWithSetting executes a query with the query options and commit all columns data. // NOTE: only use for insert query InsertStreamWithOption(ctx context.Context, query string, queryOptions *chconn.QueryOptions) (chconn.InsertStmt, error) // Conn get the underlying chconn.Conn Conn() chconn.Conn // Hijack assumes ownership of the connection from the pool. Caller is responsible for closing the connection. Hijack // will panic if called on an already released or hijacked connection. Hijack() chconn.Conn Ping(ctx context.Context) error }
Conn is an acquired *chconn.Conn from a Pool.
type Pool ¶
type Pool interface { // Close closes all connections in the pool and rejects future Acquire calls. Blocks until all connections are returned // to pool and closed. Close() Acquire(ctx context.Context) (Conn, error) // AcquireFunc acquires a *Conn and calls f with that *Conn. ctx will only affect the Acquire. It has no effect on the // call of f. The return value is either an error acquiring the Conn or the return value of f. The Conn is // automatically released after the call of f. AcquireFunc(ctx context.Context, f func(Conn) error) error // AcquireAllIdle atomically acquires all currently idle connections. Its intended use is for health check and // keep-alive functionality. It does not update pool statistics. AcquireAllIdle(ctx context.Context) []Conn // Exec executes a query without returning any rows. // NOTE: don't use it for insert and select query Exec(ctx context.Context, query string) error // ExecWithOption executes a query without returning any rows with Query options. // NOTE: don't use it for insert and select query ExecWithOption( ctx context.Context, query string, queryOptions *chconn.QueryOptions, ) error // Insert executes a insert query and commit all columns data. // // If the query is successful, the columns buffer will be reset. // // NOTE: only use for insert query Insert(ctx context.Context, query string, columns ...column.ColumnBasic) error // InsertWithOption executes a insert query with the query options and commit all columns data. // // If the query is successful, the columns buffer will be reset. // // NOTE: only use for insert query InsertWithOption(ctx context.Context, query string, queryOptions *chconn.QueryOptions, columns ...column.ColumnBasic) error // Insert executes a insert query and return a InsertStmt. // // NOTE: only use for insert query InsertStream(ctx context.Context, query string) (chconn.InsertStmt, error) // InsertWithOption executes a insert query with the query options and return a InsertStmt. // // If the query is successful, the columns buffer will be reset. // // NOTE: only use for insert query InsertStreamWithOption( ctx context.Context, query string, queryOptions *chconn.QueryOptions) (chconn.InsertStmt, error) // Select executes a query and return select stmt. // // NOTE: only use for select query Select(ctx context.Context, query string, columns ...column.ColumnBasic) (chconn.SelectStmt, error) // Select executes a query with the the query options and return select stmt. // // NOTE: only use for select query SelectWithOption( ctx context.Context, query string, queryOptions *chconn.QueryOptions, columns ...column.ColumnBasic, ) (chconn.SelectStmt, error) // Ping sends a ping to check that the connection to the server is alive. Ping(ctx context.Context) error // Stat returns a chpool.Stat struct with a snapshot of Pool statistics. Stat() *Stat // Reset closes all connections, but leaves the pool open. It is intended for use when an error is detected that would // disrupt all connections (such as a network interruption or a server state change). // // It is safe to reset a pool while connections are checked out. Those connections will be closed when they are returned // to the pool. Reset() // Config returns a copy of config that was used to initialize this pool. Config() *Config }
Pool is a connection pool for chconn
func NewWithConfig ¶
NewWithConfig creates a new Pool. config must have been created by ParseConfig.
type Stat ¶
type Stat struct {
// contains filtered or unexported fields
}
Stat is a snapshot of Pool statistics.
func (*Stat) AcquireCount ¶
AcquireCount returns the cumulative count of successful acquires from the pool.
func (*Stat) AcquireDuration ¶
AcquireDuration returns the total duration of all successful acquires from the pool.
func (*Stat) AcquiredConns ¶
AcquiredConns returns the number of currently acquired connections in the pool.
func (*Stat) CanceledAcquireCount ¶
CanceledAcquireCount returns the cumulative count of acquires from the pool that were canceled by a context.
func (*Stat) ConstructingConns ¶
ConstructingConns returns the number of conns with construction in progress in the pool.
func (*Stat) EmptyAcquireCount ¶
EmptyAcquireCount returns the cumulative count of successful acquires from the pool that waited for a resource to be released or constructed because the pool was empty.
func (*Stat) MaxIdleDestroyCount ¶
MaxIdleDestroyCount returns the cumulative count of connections destroyed because they exceeded MaxConnIdleTime.
func (*Stat) MaxLifetimeDestroyCount ¶
MaxLifetimeDestroyCount returns the cumulative count of connections destroyed because they exceeded MaxConnLifetime.
func (*Stat) NewConnsCount ¶
NewConnsCount returns the cumulative count of new connections opened.
func (*Stat) TotalConns ¶
TotalConns returns the total number of resources currently in the pool. The value is the sum of ConstructingConns, AcquiredConns, and IdleConns.