Skip to content

feat(engine): retype DecrementGuard to Arc<BarrierState> (DG-3.c) - #4845

Merged
oferchen merged 1 commit into
masterfrom
feat/dg-3c-decrementguard-barrierstate
May 24, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/dg-3c-decrementguard-barrierstate

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Routes the per-slot decrement-guard Arc through the bookkeeping allocation (BarrierState) instead of the transitional SlotBarrier adapter, closing the cross-Arc release race that DG-2.a Option B was designed to eliminate.

  • DecrementGuard.barrier: Arc<SlotBarrier> -> Arc<BarrierState>. The worker's lingering guard clone now lives on a strong-count graph disjoint from Arc<SlotData>, so the flusher's Arc::try_unwrap on the payload Arc no longer races the guard's drop body.
  • SlotHandle::new: sources the bookkeeping clone via a new SlotBarrier::barrier() accessor and hands it to the guard. SlotHandle itself keeps its Arc<SlotBarrier> field for the lock path; the handle retype is deferred to a follow-on DG-3.x task per the staging plan.
  • SlotBarrier::decrement_inflight: removed (dead after the retype). The guard now calls BarrierState::decrement_inflight directly. SlotBarrier::increment_inflight stays - SlotHandle::new still uses it.
  • Public API and wire behaviour: unchanged. The concurrent_register_and_dispatch_on_overlapping_files stress test and the flush_workers_survives_spurious_wakeup test still exercise the same Arc graph; the latter already reads entry.barrier directly (DG-3.b) so its notify path is unaffected.

Why

The DG-1 audit (docs/design/decrementguard-audit.md section 4) traced the finish_file release race to one Arc graph carrying two unrelated ownership obligations - notify-via-condvar and payload-unwrap-via-try_unwrap. DG-3.a/b set up the split (SlotData + BarrierState behind SlotEntry), but until this change the worker's DecrementGuard still travelled on the SlotBarrier adapter. Because slot_for mints a fresh adapter per call, every clone of that adapter kept the Arc<SlotData> strong count above 1 across the flusher's unwrap window. Retyping the guard to Arc<BarrierState> directly is the structural fix; the drain.rs spin-then-yield workaround (DG-4 territory) stays in place for now.

References

Test plan

  • CI fmt + clippy
  • CI nextest (stable) - flush_workers_survives_spurious_wakeup, flush_workers_blocks_until_worker_drops_arc, drain_inflight_drains_all_files, finish_file_calls_flush_workers_internally all stay green
  • CI nextest (stable) - concurrent_register_and_dispatch_on_overlapping_files stress test still passes
  • CI Windows / macOS / Linux musl

@github-actions github-actions Bot added the enhancement New feature or request label 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 force-pushed the feat/dg-3c-decrementguard-barrierstate branch from 79ec306 to 4ec0782 Compare May 24, 2026 09:31
@oferchen
oferchen merged commit 987da91 into master May 24, 2026
oferchen added a commit that referenced this pull request May 24, 2026
…(DG-3.d)

Pin the DG-2.a Option-B strong-count invariant at the actual
Arc::try_unwrap call site in drain.rs::finish_file. After DG-3.c
(#4845) retyped DecrementGuard.barrier to Arc<BarrierState>, the
worker's lingering decrement-guard clone lives on a disjoint
allocation from the payload Arc the flusher unwraps.

Three regression tests cover:

- finish_file_payload_arc_uncontended_after_worker_drop:
  deterministic three-channel handshake pins the moment the worker
  has fully retired its SlotHandle; asserts entry.data strong count
  is exactly 1 (DashMap only) and finish_file succeeds.
- finish_file_payload_arc_uncontended_under_burst: 32 serial
  apply_one_chunk calls; asserts the per-iteration post-drop count
  returns to 1.
- finish_file_payload_and_barrier_arcs_are_distinct_allocations:
  structural witness via Arc::as_ptr that the Option-B split is
  intact at the type level.

Audit at docs/audits/dg-3d-finish-file-uncontended.md enumerates
every Arc<SlotData> clone path and the worker drop sequence,
confirming the spin-then-yield workaround in drain.rs is now a
no-op on every successful path and DG-4 (spin removal) is unblocked.
oferchen added a commit that referenced this pull request May 24, 2026
…(DG-3.d) (#4855)

* test(engine): verify finish_file try_unwrap uncontended after DG-3.c (DG-3.d)

Pin the DG-2.a Option-B strong-count invariant at the actual
Arc::try_unwrap call site in drain.rs::finish_file. After DG-3.c
(#4845) retyped DecrementGuard.barrier to Arc<BarrierState>, the
worker's lingering decrement-guard clone lives on a disjoint
allocation from the payload Arc the flusher unwraps.

Three regression tests cover:

- finish_file_payload_arc_uncontended_after_worker_drop:
  deterministic three-channel handshake pins the moment the worker
  has fully retired its SlotHandle; asserts entry.data strong count
  is exactly 1 (DashMap only) and finish_file succeeds.
- finish_file_payload_arc_uncontended_under_burst: 32 serial
  apply_one_chunk calls; asserts the per-iteration post-drop count
  returns to 1.
- finish_file_payload_and_barrier_arcs_are_distinct_allocations:
  structural witness via Arc::as_ptr that the Option-B split is
  intact at the type level.

Audit at docs/audits/dg-3d-finish-file-uncontended.md enumerates
every Arc<SlotData> clone path and the worker drop sequence,
confirming the spin-then-yield workaround in drain.rs is now a
no-op on every successful path and DG-4 (spin removal) is unblocked.

* style(engine): apply rustfmt to DG-3.d test additions
@oferchen
oferchen deleted the feat/dg-3c-decrementguard-barrierstate branch May 28, 2026 03:37
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.
oferchen added a commit that referenced this pull request Aug 24, 2026
…(DG-3.d) (#4855)

* test(engine): verify finish_file try_unwrap uncontended after DG-3.c (DG-3.d)

Pin the DG-2.a Option-B strong-count invariant at the actual
Arc::try_unwrap call site in drain.rs::finish_file. After DG-3.c
(#4845) retyped DecrementGuard.barrier to Arc<BarrierState>, the
worker's lingering decrement-guard clone lives on a disjoint
allocation from the payload Arc the flusher unwraps.

Three regression tests cover:

- finish_file_payload_arc_uncontended_after_worker_drop:
  deterministic three-channel handshake pins the moment the worker
  has fully retired its SlotHandle; asserts entry.data strong count
  is exactly 1 (DashMap only) and finish_file succeeds.
- finish_file_payload_arc_uncontended_under_burst: 32 serial
  apply_one_chunk calls; asserts the per-iteration post-drop count
  returns to 1.
- finish_file_payload_and_barrier_arcs_are_distinct_allocations:
  structural witness via Arc::as_ptr that the Option-B split is
  intact at the type level.

Audit at docs/audits/dg-3d-finish-file-uncontended.md enumerates
every Arc<SlotData> clone path and the worker drop sequence,
confirming the spin-then-yield workaround in drain.rs is now a
no-op on every successful path and DG-4 (spin removal) is unblocked.

* style(engine): apply rustfmt to DG-3.d test additions
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