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 ReservingManager
- type Scope
- type SessionManager
- 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
MaxScannedRows int64 // deprecated alias
MaxReturnedRows int64
MaxReturnedBytes int64
MaxSessionCost int64
}
Limits is the effective budget for a scope. Zero values are unlimited.
type MemoryManager ¶
type MemoryManager struct {
// contains filtered or unexported fields
}
MemoryManager is a process-local manager with role and tenant overrides. Tenant limits take precedence over role 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.
type ReservingManager ¶
type ReservingManager interface {
Manager
AcquireWithReservation(context.Context, Scope, Reservation) (Lease, error)
}
ReservingManager supports atomic pre-execution budget reservations. Callers with cost estimates should prefer this interface over Manager.
type SessionManager ¶
SessionManager can discard all accounting for a disconnected session.
type Usage ¶
type Usage struct {
// ScannedRows is an actual observed scan count. Zero means unknown or none;
// callers must not substitute ReturnedRows for it.
ScannedRows int64
// EstimatedScannedRows is a planner estimate, not an observed scan count.
EstimatedScannedRows int64
ReturnedRows int64
ReturnedBytes int64
Duration time.Duration
Cost int64
}
Usage captures one invocation's observable resource usage.