Documentation
¶
Overview ¶
Package dbaccess bounds physical database connections shared by tenant and platform sql.DB pools in one Engine process.
Index ¶
- Variables
- func AcquireWorkAdmission(ctx context.Context, admission interface{ ... }) (context.Context, func(), error)
- func AttachWorkAdmission(ctx context.Context, release func()) (context.Context, func())
- func BeginAdmittedTx(ctx context.Context, database *sql.DB, admission interface{ ... }) (*sql.Tx, func(), error)
- func HasWorkAdmission(ctx context.Context) bool
- func Open(driverName, dsn string) (*sql.DB, error)
- func ServerKey(driverName, dsn string) string
- func Snapshots() map[string]Snapshot
- type Admission
- type AdmissionSnapshot
- type Budget
- type Config
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
HasWorkAdmission reports whether the context is currently covered by an active admission permit. A released stream-authentication permit is false.
func Open ¶
Open creates a database/sql pool whose physical driver connections share a bounded process budget with every other pool targeting the same server.
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 ¶
AdmissionFor returns the unit-of-work limiter shared by pools that target the same endpoint identity.
func NewAdmission ¶
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 ¶
Acquire reserves one work slot. Always release after the complete unit of work, including its transaction commit or rollback.
func (*Admission) AcquireMaintenance ¶
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 (*Budget) Acquire ¶
Acquire reserves one physical connection slot until the returned release function is called. Wait count and duration are both bounded.
func (*Budget) WorkAdmission ¶
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 ¶
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.