internal/migrate/connectionbound.go
internal/migrate · 95 lines · 5 declarations · source
Declarations
var ErrConnectionBudget
var ErrConnectionBudget = errors.New("the deployment's connection demand exceeds the server's slots")
ErrConnectionBudget is a deployment that asked for more than the substrate has.
type ConnectionBudget
type ConnectionBudget struct {
// MaxConnections and Reserved are the server's own settings. Reserved is subtracted because
// those slots are for superuser recovery: a runtime role that counted on them would find the
// ceiling lower than it computed, at the moment an administrator most needs to get in.
MaxConnections int
Reserved int
// InUse is every client backend on the server, not only this database and not only this role.
// A pooler, a replica's monitoring session and an operator's psql all take from the same pool,
// and a check that counted only its own kind would pass a server that is already full.
InUse int
// Wanted is this process's pool maximum: what it may open, not what it has opened.
Wanted int
}
ConnectionBudget is what the check saw, so an operator is told both numbers rather than one.
method ConnectionBudget.Available
func (b ConnectionBudget) Available() int
Available is what is left for this process after the server's reservation and everyone else.
method ConnectionBudget.String
func (b ConnectionBudget) String() string
func CheckConnectionBudget
func CheckConnectionBudget(ctx context.Context, pool *pgxpool.Pool) (ConnectionBudget, error)
CheckConnectionBudget refuses a pool the server could not satisfy.
Called after the pool is built and before anything is served, on the same pool, so the connection it uses is one of the ones being counted — which is the conservative direction: the check pays for itself out of its own budget rather than assuming a slot it has not taken.