Spectre.GAM.Kernel.Meter (Spectre v0.4.0)

Copy Markdown View Source

Pure, conservative accounting for Mandate resource limits.

Every operation consumes a typed Meter.Account and preserves:

ceiling = available + reserved + suspended + spent + delegated

Quantities move between buckets; they are never inferred or created. A parent's delegated quantity becomes a child's ceiling, so delegation is subtractive rather than a second issuance of authority.

suspended is never released by time or restart. It moves only through an explicit Duty disposition or definitive late Outcome.

Summary

Functions

Returns whether quantity can currently be reserved.

Transfers quantity subtractively from a parent to a child allocation.

Returns all currently free child quantity to its parent.

Returns only free child quantity to its parent.

Validates a canonical reservation request against current balances.

Conservatively takes back released quantities that remain available.

Returns reserved quantity only after definitive no-effect Evidence.

Moves quantity from available to reserved.

Plans and applies several reservations as one pure transition.

Resolves suspended quantity under an explicit durable disposition.

Moves a definitive effected quantity from reserved to spent.

Moves an ambiguous reservation from reserved to suspended.

Validates a typed account and its conservation equation.

Types

accounts()

@type accounts() :: %{optional(String.t()) => Spectre.GAM.Kernel.Meter.Account.t()}

reason()

@type reason() :: term()

Functions

available?(account, quantity)

Returns whether quantity can currently be reserved.

delegate(parent, child, quantity)

Transfers quantity subtractively from a parent to a child allocation.

Both accounts must represent the same Meter. The parent moves available -> delegated; the child's ceiling and available grow by the same quantity.

devolve(parent, child)

Returns all currently free child quantity to its parent.

devolve(parent, child, quantity)

Returns only free child quantity to its parent.

Reserved and suspended quantities remain bound to their Attempt or Duty, and spent remains historical. Only available can therefore be devolved.

plan_reservations(requests, accounts)

@spec plan_reservations(Spectre.GAM.Kernel.Meter.Amounts.t(), accounts()) ::
  {:ok, Spectre.GAM.Kernel.Meter.Amounts.t()} | {:error, reason()}

Validates a canonical reservation request against current balances.

recontain_many(requests, accounts)

Conservatively takes back released quantities that remain available.

The returned maps partition every request into recontained and deficits. A deficit is reported without inventing quantity or violating conservation.

release(account, quantity)

Returns reserved quantity only after definitive no-effect Evidence.

reserve(account, quantity)

Moves quantity from available to reserved.

reserve_many(requests, accounts)

@spec reserve_many(Spectre.GAM.Kernel.Meter.Amounts.t(), accounts()) ::
  {:ok, accounts(), Spectre.GAM.Kernel.Meter.Amounts.t()} | {:error, reason()}

Plans and applies several reservations as one pure transition.

resolve_suspended(account, quantity, disposition)

@spec resolve_suspended(
  Spectre.GAM.Kernel.Meter.Account.t(),
  non_neg_integer(),
  :settle | :release
) ::
  {:ok, Spectre.GAM.Kernel.Meter.Account.t()} | {:error, reason()}

Resolves suspended quantity under an explicit durable disposition.

:settle acknowledges it as spent; :release makes it available again.

settle(account, quantity)

Moves a definitive effected quantity from reserved to spent.

suspend(account, quantity)

Moves an ambiguous reservation from reserved to suspended.

validate(account)

@spec validate(Spectre.GAM.Kernel.Meter.Account.t()) :: :ok | {:error, reason()}

Validates a typed account and its conservation equation.