dbaccess

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dbaccess bounds physical database connections shared by tenant and platform sql.DB pools in one Engine process.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExhausted = errors.New("database connection budget exhausted")
)

Functions

func AcquireWorkAdmission

func AcquireWorkAdmission(ctx context.Context, admission interface {
	Acquire(context.Context) (func(), error)
}) (context.Context, func(), error)

AcquireWorkAdmission reuses a live context permit or acquires exactly one permit and attaches it to the returned context.

func AttachWorkAdmission

func AttachWorkAdmission(ctx context.Context, release func()) (context.Context, func())

AttachWorkAdmission records an already-acquired unit-of-work permit on its context. The returned release is idempotent and marks the context inactive before returning the permit.

func BeginAdmittedTx

func BeginAdmittedTx(ctx context.Context, database *sql.DB, admission interface {
	Acquire(context.Context) (func(), error)
}) (*sql.Tx, func(), error)

BeginAdmittedTx acquires or reuses one tenant work permit and holds it until the caller releases the returned callback after transaction completion.

func HasWorkAdmission

func HasWorkAdmission(ctx context.Context) bool

HasWorkAdmission reports whether the context is currently covered by an active admission permit. A released stream-authentication permit is false.

func Open

func Open(driverName, dsn string) (*sql.DB, error)

Open creates a database/sql pool whose physical driver connections share a bounded process budget with every other pool targeting the same server.

func ServerKey

func ServerKey(driverName, dsn string) string

ServerKey groups pools by physical endpoint. Operators sharing one backend through DNS aliases or proxies can set KORA_DB_BUDGET_KEY identically on all participating Engine processes to force a common allocation identity.

func Snapshots

func Snapshots() map[string]Snapshot

Snapshots returns a point-in-time view of each process-local endpoint budget. The set is bounded by the configured database endpoints, not tenant request cardinality.

Types

type Admission

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

Admission independently limits active work. It is intentionally separate from physical connection permits: one admitted operation can perform nested queries or reuse a transaction without acquiring another permit.

func AdmissionFor

func AdmissionFor(driverName, dsn string) (*Admission, error)

AdmissionFor returns the unit-of-work limiter shared by pools that target the same endpoint identity.

func NewAdmission

func NewAdmission(capacity, maxWaiters int, wait time.Duration) (*Admission, error)

func NewAdmissionWithMaintenance

func NewAdmissionWithMaintenance(capacity, maxWaiters int, wait time.Duration, maintenanceCapacity int) (*Admission, error)

NewAdmissionWithMaintenance reserves a separate bounded lane for heavy maintenance work. Ordinary work cannot consume the reserved maintenance slot, and maintenance concurrency cannot exceed maintenanceCapacity.

func (*Admission) Acquire

func (a *Admission) Acquire(ctx context.Context) (func(), error)

Acquire reserves one work slot. Always release after the complete unit of work, including its transaction commit or rollback.

func (*Admission) AcquireMaintenance

func (a *Admission) AcquireMaintenance(ctx context.Context) (func(), error)

AcquireMaintenance admits a heavy maintenance unit in the separately bounded lane. A zero-capacity lane rejects maintenance rather than allowing unbounded fan-out through the ordinary lane.

func (*Admission) Snapshot

func (a *Admission) Snapshot() AdmissionSnapshot

type AdmissionSnapshot

type AdmissionSnapshot struct {
	Capacity            int
	Active              int
	MaintenanceActive   int
	MaintenanceCapacity int
	Waiters             int
	WaitCount           uint64
	WaitDuration        time.Duration
	Rejected            uint64
}

AdmissionSnapshot reports active and queued unit-of-work counts.

type Budget

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

Budget is shared by all sql.DB pools that target the same physical server.

func New

func New(cfg Config) (*Budget, error)

func (*Budget) Acquire

func (b *Budget) Acquire(ctx context.Context) (func(), error)

Acquire reserves one physical connection slot until the returned release function is called. Wait count and duration are both bounded.

func (*Budget) Snapshot

func (b *Budget) Snapshot() Snapshot

func (*Budget) WorkAdmission

func (b *Budget) WorkAdmission() *Admission

WorkAdmission returns the active-work limiter associated with this physical endpoint's connection allocation.

type Config

type Config struct {
	MaxConnections int
	MaxWaiters     int
	Wait           time.Duration
	MaxActiveWork  int
	MaxWorkWaiters int
	WorkWait       time.Duration
	MaxHeavyJobs   int
}

Config bounds concurrent physical connections and connector waiters. A waiter is rejected when MaxWaiters is reached and times out after Wait.

func ConfigFromEnv

func ConfigFromEnv() (Config, error)

ConfigFromEnv derives a per-process share of an optional physical-server connection budget. When KORA_DB_SERVER_MAX_CONNECTIONS is configured, the reserved connections are removed first and the remainder is divided by the declared replica count. Every Engine replica must use the same values.

type Snapshot

type Snapshot struct {
	Capacity          int
	InUse             int
	Waiters           int
	WaitCount         uint64
	WaitDuration      time.Duration
	Rejected          uint64
	OperationCount    uint64
	OperationDuration time.Duration
	LockContention    uint64
	Work              AdmissionSnapshot
}

Snapshot contains bounded-cardinality process-local diagnostics.

Jump to

Keyboard shortcuts

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