GenDurable.Limiter.Postgres (gen_durable v0.2.12)

Copy Markdown View Source

The default GenDurable.Limiter backend: the sharded gen_durable_buckets table.

Same admission math as the old fused pick (the c_*/r_* CTEs), but run as standalone statements over an already-claimed batch instead of welded into the claim:

  • admit/2 — sourced from the claimed batch (passed as arrays) instead of cand; RETURNS the admit decision per id (and the concurrency shard it drew) instead of claiming rows. Debits the taken rate tokens / concurrency slots.
  • credit/2 — a standalone available = LEAST(capacity, available + n) per slot, replacing the outcome's credit_gate rider. LEAST (not the rider's bare + 1) guards the out-of-band case: a credit racing a reconcile that already repaired the counter to full must not trip the available <= capacity CHECK.
  • sync_config/2 / reconcile/2 — delegate to the existing Queries machinery (upsert_*_configs, gc_buckets + reconcile_concurrency).

The handle is %{repo: repo}.

Retry discipline: the K=1 arbiter violation now aborts the CLAIM (handled in Queries.pick); admit/2 can still trip the buckets CHECK (a residual gate over-admission, see c_ranges) or the buckets PK (two picks minting the same cold rate key), so it retries itself warm — the same three-strike, constraint-resolved discipline.