Skip to content

feat(engine): add BarrierState + SlotData types per DG-2.a spec (DG-3.a) - #4826

Merged
oferchen merged 1 commit into
masterfrom
feat/dg-3a-barrierstate-slotdata-types
May 24, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/dg-3a-barrierstate-slotdata-types

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

First step of DG-3: introduce the Option-B types specified in
docs/design/dg-2a-option-b-spec.md
alongside the existing SlotBarrier. Purely additive; no call site is
touched.

The DG-1 audit
(docs/design/decrementguard-audit.md)
traced the finish_file release race in
crates/engine/src/concurrent_delta/parallel_apply.rs to a single
Arc<SlotBarrier> graph carrying two unrelated ownership obligations
(unwrap the payload + decrement the counter). DG-2.a's Option B splits
those obligations across two Arcs whose strong-count trajectories are
independent. DG-2.b sequences the migration; DG-2.c chose the
single-PR atomic strategy. This PR delivers DG-3.a from that plan:
type definitions only.

New types in crates/engine/src/concurrent_delta/parallel_apply/slot_barrier.rs:

  • BarrierState - in-flight counter + Condvar (the notify-bearing half).
  • SlotData - per-file payload behind its own mutex (the unwrap-bearing half).
  • SlotEntry - DashMap value carrying both Arcs.
  • SlotHandle (parallel to the mod-level SlotHandle) - the post-split
    handle DG-3.c will rename into the mod-level slot once DecrementGuard
    is retyped. The spec's _decrement: DecrementGuard field is intentionally
    deferred to DG-3.c because the existing DecrementGuard still holds
    Arc<SlotBarrier>; attaching it now would defeat the split.

All four types are pub(super), gated with #[allow(dead_code)] so the
production build does not warn while DG-3.b/c/d wire the callers. Each
type has a #[cfg(test)] smoke test that exercises its single obvious
operation (BarrierState::wait_until_idle unblocks after decrement_inflight,
SlotData::lock_slot + into_slot round-trip, SlotHandle::new bumps
the entry's counter and exposes lock_slot).

The existing SlotBarrier, DecrementGuard, and mod-level SlotHandle
remain unchanged. The spin-then-yield workaround at finish_file is
untouched (DG-4 removes it once DG-3.d lands).

Subsequent steps:

  • DG-3.b swaps the DashMap value type from Arc<SlotBarrier> to
    SlotEntry and updates register_file, slot_for, flush_workers.
  • DG-3.c retypes DecrementGuard.barrier to Arc<BarrierState> and
    folds the post-split SlotHandle into the mod-level slot, attaching
    the _decrement field.
  • DG-3.d rewrites finish_file to Arc::try_unwrap(entry.data)
    and removes the spin loop.
  • DG-4 retires the workaround comment block.

Test plan

  • CI builds the engine crate on every supported target (Linux musl,
    macOS, Windows) with the new types present but uncalled.
  • CI runs the three smoke tests under dg_3a_tests in the nextest
    job (barrier_state_wait_until_idle_returns_after_decrement,
    slot_data_lock_then_into_slot,
    slot_handle_constructor_increments_inflight).
  • CI fmt + clippy gate confirms no warning regressions from the
    new doc comments or #[allow(dead_code)] placement.

@github-actions github-actions Bot added the enhancement New feature or request label May 24, 2026
@oferchen
oferchen force-pushed the feat/dg-3a-barrierstate-slotdata-types branch 3 times, most recently from 0e40324 to 0e6b317 Compare May 24, 2026 01:26
Introduces the Option-B types specified in
`docs/design/dg-2a-option-b-spec.md` (BarrierState, SlotData,
SlotEntry, and the post-split SlotHandle) alongside the existing
SlotBarrier. This is the type-definition-only first step of DG-3;
no call site is migrated. DG-3.b will swap the DashMap value type,
DG-3.c will retype DecrementGuard and the mod-level SlotHandle, and
DG-3.d will collapse the finish_file spin loop. Each new type
carries a smoke test that exercises its single obvious operation.
@oferchen
oferchen force-pushed the feat/dg-3a-barrierstate-slotdata-types branch from 0e6b317 to df8be7b Compare May 24, 2026 01:27
@oferchen
oferchen merged commit 28fb072 into master May 24, 2026
58 checks passed
oferchen added a commit that referenced this pull request May 24, 2026
Routes the per-slot decrement-guard Arc through the bookkeeping
allocation (`BarrierState`) instead of the transitional `SlotBarrier`
adapter. After DG-3.b moved the canonical per-file state into
`SlotEntry { data: Arc<SlotData>, barrier: Arc<BarrierState> }`, the
worker's lingering `DecrementGuard` clone still rode on the adapter
Arc, which - because the adapter clones both inner Arcs on every
`slot_for` call - kept the payload Arc's strong count above 1 across
the flusher's `Arc::try_unwrap` window. DG-3.c retypes
`DecrementGuard.barrier` to `Arc<BarrierState>` so the guard's clone
lives on a strong-count graph disjoint from `Arc<SlotData>`, closing
the cross-Arc release race that the DG-2.a Option-B spec
(`docs/design/dg-2a-option-b-spec.md` section 2) was designed to
eliminate.

`SlotHandle::new` now sources the bookkeeping clone via a new
`SlotBarrier::barrier()` accessor and hands it to the guard; the
handle itself keeps its `Arc<SlotBarrier>` field for the lock path so
the `SlotHandle` retype can sequence independently in a follow-on
DG-3.x task. The now-dead forwarding `SlotBarrier::decrement_inflight`
is removed - the guard talks to `BarrierState::decrement_inflight`
directly. Public API and wire behaviour unchanged.

Related: DG-3.a (#4826), DG-3.b (#4841), DG-2.a spec.
oferchen added a commit that referenced this pull request May 24, 2026
)

Routes the per-slot decrement-guard Arc through the bookkeeping
allocation (`BarrierState`) instead of the transitional `SlotBarrier`
adapter. After DG-3.b moved the canonical per-file state into
`SlotEntry { data: Arc<SlotData>, barrier: Arc<BarrierState> }`, the
worker's lingering `DecrementGuard` clone still rode on the adapter
Arc, which - because the adapter clones both inner Arcs on every
`slot_for` call - kept the payload Arc's strong count above 1 across
the flusher's `Arc::try_unwrap` window. DG-3.c retypes
`DecrementGuard.barrier` to `Arc<BarrierState>` so the guard's clone
lives on a strong-count graph disjoint from `Arc<SlotData>`, closing
the cross-Arc release race that the DG-2.a Option-B spec
(`docs/design/dg-2a-option-b-spec.md` section 2) was designed to
eliminate.

`SlotHandle::new` now sources the bookkeeping clone via a new
`SlotBarrier::barrier()` accessor and hands it to the guard; the
handle itself keeps its `Arc<SlotBarrier>` field for the lock path so
the `SlotHandle` retype can sequence independently in a follow-on
DG-3.x task. The now-dead forwarding `SlotBarrier::decrement_inflight`
is removed - the guard talks to `BarrierState::decrement_inflight`
directly. Public API and wire behaviour unchanged.

Related: DG-3.a (#4826), DG-3.b (#4841), DG-2.a spec.
@oferchen
oferchen deleted the feat/dg-3a-barrierstate-slotdata-types branch May 28, 2026 03:37
oferchen added a commit that referenced this pull request Aug 24, 2026
….a) (#4826)

Introduces the Option-B types specified in
`docs/design/dg-2a-option-b-spec.md` (BarrierState, SlotData,
SlotEntry, and the post-split SlotHandle) alongside the existing
SlotBarrier. This is the type-definition-only first step of DG-3;
no call site is migrated. DG-3.b will swap the DashMap value type,
DG-3.c will retype DecrementGuard and the mod-level SlotHandle, and
DG-3.d will collapse the finish_file spin loop. Each new type
carries a smoke test that exercises its single obvious operation.
oferchen added a commit that referenced this pull request Aug 24, 2026
)

Routes the per-slot decrement-guard Arc through the bookkeeping
allocation (`BarrierState`) instead of the transitional `SlotBarrier`
adapter. After DG-3.b moved the canonical per-file state into
`SlotEntry { data: Arc<SlotData>, barrier: Arc<BarrierState> }`, the
worker's lingering `DecrementGuard` clone still rode on the adapter
Arc, which - because the adapter clones both inner Arcs on every
`slot_for` call - kept the payload Arc's strong count above 1 across
the flusher's `Arc::try_unwrap` window. DG-3.c retypes
`DecrementGuard.barrier` to `Arc<BarrierState>` so the guard's clone
lives on a strong-count graph disjoint from `Arc<SlotData>`, closing
the cross-Arc release race that the DG-2.a Option-B spec
(`docs/design/dg-2a-option-b-spec.md` section 2) was designed to
eliminate.

`SlotHandle::new` now sources the bookkeeping clone via a new
`SlotBarrier::barrier()` accessor and hands it to the guard; the
handle itself keeps its `Arc<SlotBarrier>` field for the lock path so
the `SlotHandle` retype can sequence independently in a follow-on
DG-3.x task. The now-dead forwarding `SlotBarrier::decrement_inflight`
is removed - the guard talks to `BarrierState::decrement_inflight`
directly. Public API and wire behaviour unchanged.

Related: DG-3.a (#4826), DG-3.b (#4841), DG-2.a spec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant