Documentation
¶
Overview ¶
Package budget provides role/tenant scoped execution budgets.
Index ¶
- Variables
- type Lease
- type Limits
- type Manager
- type MemoryManager
- func (m *MemoryManager) Acquire(ctx context.Context, scope Scope) (Lease, error)
- func (m *MemoryManager) AcquireWithReservation(ctx context.Context, scope Scope, reservation Reservation) (Lease, error)
- func (m *MemoryManager) CloseSession(session string)
- func (m *MemoryManager) ConfiguredLimits() (map[string]Limits, map[string]Limits)
- func (m *MemoryManager) UpdateLimits(roles, tenants map[string]Limits)
- type Reservation
- type Scope
- type Usage
Constants ¶
This section is empty.
Variables ¶
var ErrExceeded = errors.New("resource budget exceeded")
ErrExceeded is returned when a configured resource budget is exceeded.
Functions ¶
This section is empty.
Types ¶
type Limits ¶
type Limits struct {
MaxConcurrent int
MaxExecution time.Duration
MaxEstimatedScannedRows int64
MaxReturnedRows int64
MaxReturnedBytes int64
MaxSessionCost int64
}
Limits is the effective budget for a scope. Zero values are unlimited.
type Manager ¶
type Manager interface {
AcquireWithReservation(context.Context, Scope, Reservation) (Lease, error)
}
Manager acquires scoped budgets, atomically holding a pre-execution reservation until the lease completes.
type MemoryManager ¶
type MemoryManager struct {
// contains filtered or unexported fields
}
MemoryManager is a process-local manager with role and tenant overrides. Budgets are layered: a session's state is its principal's (Role) in one tenant; a tenant's maxConcurrent bounds the calls of all its sessions together, and its other limits tighten its sessions' field by field (see limits).
func New ¶
func New(roles, tenants map[string]Limits) *MemoryManager
New returns a manager. Empty maps mean no additional rejection.
func NewWithBounds ¶
func NewWithBounds(roles, tenants map[string]Limits, ttl time.Duration, maxStates int) *MemoryManager
NewWithBounds returns a manager with bounded idle scope state.
func (*MemoryManager) AcquireWithReservation ¶
func (m *MemoryManager) AcquireWithReservation( ctx context.Context, scope Scope, reservation Reservation, ) (Lease, error)
AcquireWithReservation atomically checks and holds estimated session cost until Complete reconciles it with actual usage.
func (*MemoryManager) CloseSession ¶
func (m *MemoryManager) CloseSession(session string)
CloseSession discards idle accounting for session and marks active scopes for removal when their last lease completes.
func (*MemoryManager) ConfiguredLimits ¶
func (m *MemoryManager) ConfiguredLimits() (map[string]Limits, map[string]Limits)
ConfiguredLimits returns copies of the current role and tenant limits.
func (*MemoryManager) UpdateLimits ¶
func (m *MemoryManager) UpdateLimits(roles, tenants map[string]Limits)
UpdateLimits atomically replaces configured role and tenant limits while retaining all in-flight and accumulated session state.
type Reservation ¶
Reservation is a pre-execution estimate held against a session until its lease is completed and reconciled with actual Usage.