Documentation ¶
Index ¶
- Constants
- Variables
- func IsResettableError(ctx context.Context, err error) bool
- func IsRetryableError(ctx context.Context, err error) bool
- type MaxRetryError
- type NodeConnectionBalancer
- type NodeHealthTracker
- type ResettableError
- type RetryPool
- func (p *RetryPool) AcquireAllIdle(ctx context.Context) []*pgxpool.Conn
- func (p *RetryPool) BeginFunc(ctx context.Context, txFunc func(pgx.Tx) error) error
- func (p *RetryPool) BeginTxFunc(ctx context.Context, txOptions pgx.TxOptions, txFunc func(pgx.Tx) error) error
- func (p *RetryPool) Close()
- func (p *RetryPool) Config() *pgxpool.Config
- func (p *RetryPool) ExecFunc(ctx context.Context, ...) error
- func (p *RetryPool) GC(conn *pgx.Conn)
- func (p *RetryPool) ID() string
- func (p *RetryPool) MaxConns() uint32
- func (p *RetryPool) MinConns() uint32
- func (p *RetryPool) Node(conn *pgx.Conn) uint32
- func (p *RetryPool) QueryFunc(ctx context.Context, rowsFunc func(ctx context.Context, rows pgx.Rows) error, ...) error
- func (p *RetryPool) QueryRowFunc(ctx context.Context, rowFunc func(ctx context.Context, row pgx.Row) error, ...) error
- func (p *RetryPool) Range(f func(conn *pgx.Conn, nodeID uint32))
- func (p *RetryPool) Stat() *pgxpool.Stat
- type RetryableError
Constants ¶
const ( // https://www.cockroachlabs.com/docs/stable/common-errors.html#restart-transaction CrdbRetryErrCode = "40001" // https://www.cockroachlabs.com/docs/stable/common-errors.html#result-is-ambiguous CrdbAmbiguousErrorCode = "40003" // https://www.cockroachlabs.com/docs/stable/node-shutdown.html#connection-retry-loop CrdbServerNotAcceptingClients = "57P01" // Error when SqlState is unknown CrdbUnknownSQLState = "XXUUU" // Error message encountered when crdb nodes have large clock skew CrdbClockSkewMessage = "cannot specify timestamp in the future" )
Variables ¶
var CtxDisableRetries ctxDisableRetries
Functions ¶
func IsResettableError ¶ added in v1.25.0
IsResettableError returns whether the given CRDB error is a resettable error.
Types ¶
type MaxRetryError ¶
MaxRetryError is returned when the retry budget is exhausted.
func (*MaxRetryError) Error ¶
func (e *MaxRetryError) Error() string
func (*MaxRetryError) GRPCStatus ¶ added in v1.29.0
func (e *MaxRetryError) GRPCStatus() *status.Status
func (*MaxRetryError) Unwrap ¶
func (e *MaxRetryError) Unwrap() error
type NodeConnectionBalancer ¶
type NodeConnectionBalancer struct {
// contains filtered or unexported fields
}
NodeConnectionBalancer attempts to keep the connections managed by a RetryPool balanced between healthy nodes in a Cockroach cluster. It asynchronously processes idle connections, and kills any to nodes that have too many. When the pool reconnects, it will have a different balance of connections, and over time the balancer will bring the counts close to equal.
func NewNodeConnectionBalancer ¶
func NewNodeConnectionBalancer(pool *RetryPool, healthTracker *NodeHealthTracker, interval time.Duration) *NodeConnectionBalancer
NewNodeConnectionBalancer builds a new nodeConnectionBalancer for a given connection pool and health tracker.
type NodeHealthTracker ¶
NodeHealthTracker detects changes in the node pool by polling the cluster periodically and recording the node ids that are seen. This is used to detect new nodes that come online that have either previously been marked unhealthy due to connection errors or due to scale up.
Consumers can manually mark a node healthy or unhealthy as well.
func NewNodeHealthChecker ¶
func NewNodeHealthChecker(url string) (*NodeHealthTracker, error)
NewNodeHealthChecker builds a health checker that polls the cluster at the given url.
func (*NodeHealthTracker) HealthyNodeCount ¶
func (t *NodeHealthTracker) HealthyNodeCount() int
HealthyNodeCount returns the number of healthy nodes currently tracked.
func (*NodeHealthTracker) IsHealthy ¶
func (t *NodeHealthTracker) IsHealthy(nodeID uint32) bool
IsHealthy returns true if the given nodeID has been marked healthy.
func (*NodeHealthTracker) Poll ¶
func (t *NodeHealthTracker) Poll(ctx context.Context, interval time.Duration)
Poll starts polling the cluster and recording the node IDs that it sees.
func (*NodeHealthTracker) SetNodeHealth ¶
func (t *NodeHealthTracker) SetNodeHealth(nodeID uint32, healthy bool)
SetNodeHealth marks a node as either healthy or unhealthy.
type ResettableError ¶
type ResettableError struct {
Err error
}
ResettableError is an error that we think may succeed if retried against a new connection.
func (*ResettableError) Error ¶
func (e *ResettableError) Error() string
func (*ResettableError) GRPCStatus ¶ added in v1.29.0
func (e *ResettableError) GRPCStatus() *status.Status
func (*ResettableError) Unwrap ¶
func (e *ResettableError) Unwrap() error
type RetryPool ¶
func NewRetryPool ¶
func (*RetryPool) AcquireAllIdle ¶
AcquireAllIdle returns all idle connections from the underlying pgxpool.Pool
func (*RetryPool) BeginFunc ¶
BeginFunc is a replacement for pgxpool.BeginFunc that allows resetting the connection on error, or retrying on a retryable error.
func (*RetryPool) BeginTxFunc ¶
func (p *RetryPool) BeginTxFunc(ctx context.Context, txOptions pgx.TxOptions, txFunc func(pgx.Tx) error) error
BeginTxFunc is a replacement for pgxpool.BeginTxFunc that allows resetting the connection on error, or retrying on a retryable error.
func (*RetryPool) ExecFunc ¶
func (p *RetryPool) ExecFunc(ctx context.Context, tagFunc func(ctx context.Context, tag pgconn.CommandTag, err error) error, sql string, arguments ...any) error
ExecFunc is a replacement for pgxpool.Pool.Exec that allows resetting the connection on error, or retrying on a retryable error.
func (*RetryPool) GC ¶
func (p *RetryPool) GC(conn *pgx.Conn)
GC marks a connection for destruction on the next Acquire. BeforeAcquire can signal to the pool to close the connection and clean up the reference in the pool at the same time, so we lazily GC connections instead of closing the connection directly.
func (*RetryPool) QueryFunc ¶
func (p *RetryPool) QueryFunc(ctx context.Context, rowsFunc func(ctx context.Context, rows pgx.Rows) error, sql string, optionsAndArgs ...any) error
QueryFunc is a replacement for pgxpool.Pool.Query that allows resetting the connection on error, or retrying on a retryable error.
func (*RetryPool) QueryRowFunc ¶
func (p *RetryPool) QueryRowFunc(ctx context.Context, rowFunc func(ctx context.Context, row pgx.Row) error, sql string, optionsAndArgs ...any) error
QueryRowFunc is a replacement for pgxpool.Pool.QueryRow that allows resetting the connection on error, or retrying on a retryable error.
type RetryableError ¶
type RetryableError struct {
Err error
}
RetryableError is an error that can be retried against the existing connection.
func (*RetryableError) Error ¶
func (e *RetryableError) Error() string
func (*RetryableError) GRPCStatus ¶ added in v1.29.0
func (e *RetryableError) GRPCStatus() *status.Status
func (*RetryableError) Unwrap ¶
func (e *RetryableError) Unwrap() error