Skip to content

ore/pool: enforce budget for inserts turned away by single-flight#37824

Open
def- wants to merge 1 commit into
MaterializeInc:mainfrom
def-:pool-enforce-budget-single-flight-race
Open

ore/pool: enforce budget for inserts turned away by single-flight#37824
def- wants to merge 1 commit into
MaterializeInc:mainfrom
def-:pool-enforce-budget-single-flight-race

Conversation

@def-

@def- def- commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Budget enforcement in mz_ore::pool is single-flight: an insert that trips it while another pass holds the enforcing guard returns on WouldBlock, trusting the in-progress pass to enforce on its behalf. That trust is misplaced once the holder is already past its final resident_bytes read: the turned-away insert's bytes are neither seen by the holder nor enforced by the bailer, and nothing re-trips budget enforcement afterward (only a later insert or a set_budget shrink does, and the spill loop sweeps the compressed cap but not the budget). The pool then sits over budget_bytes until insert activity resumes.

Add an enforce_pending flag: a turned-away caller sets it (Release), and the holder re-runs its pass while it is set (Acquire on the swap so the re-read sees the caller's bump). This closes the last-read-to-guard-release window down to a few instructions.

Follow-up to #37718

I'm not sure if the design of this is great, I can also open a Linear issue instead if you prefer @DAlperin

Budget enforcement in `mz_ore::pool` is single-flight: an insert that trips
it while another pass holds the `enforcing` guard returns on `WouldBlock`,
trusting the in-progress pass to enforce on its behalf. That trust is
misplaced once the holder is already past its final `resident_bytes` read:
the turned-away insert's bytes are neither seen by the holder nor enforced
by the bailer, and nothing re-trips budget enforcement afterward (only a
later insert or a `set_budget` shrink does, and the spill loop sweeps the
compressed cap but not the budget). The pool then sits over `budget_bytes`
until insert activity resumes.

Add an `enforce_pending` flag: a turned-away caller sets it (Release), and
the holder re-runs its pass while it is set (Acquire on the swap so the
re-read sees the caller's bump). This closes the last-read-to-guard-release
window down to a few instructions.

The module is behind the (currently unwired) `pool` feature, so this is a
latent fix with no user-visible effect yet.

Adds a regression test, racing_insert_is_not_dropped_by_budget_single_flight,
which drives the losing interleaving deterministically via a one-shot,
test-only seam fired between the pass's final counter read and the guard
release. It fails on the pre-fix code (resident 128 KiB against a 64 KiB
budget) and passes with the flag.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@def-
def- requested a review from DAlperin July 23, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant