Repository navigation
feat(engine): retype DecrementGuard to Arc<BarrierState> (DG-3.c) - #4845
Merged
Merged
Conversation
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
force-pushed
the
feat/dg-3c-decrementguard-barrierstate
branch
from
May 24, 2026 09:31
79ec306 to
4ec0782
Compare
3 tasks
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
This was referenced May 25, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Routes the per-slot decrement-guard Arc through the bookkeeping allocation (
BarrierState) instead of the transitionalSlotBarrieradapter, 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 fromArc<SlotData>, so the flusher'sArc::try_unwrapon the payload Arc no longer races the guard's drop body.SlotHandle::new: sources the bookkeeping clone via a newSlotBarrier::barrier()accessor and hands it to the guard.SlotHandleitself keeps itsArc<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 callsBarrierState::decrement_inflightdirectly.SlotBarrier::increment_inflightstays -SlotHandle::newstill uses it.concurrent_register_and_dispatch_on_overlapping_filesstress test and theflush_workers_survives_spurious_wakeuptest still exercise the same Arc graph; the latter already readsentry.barrierdirectly (DG-3.b) so its notify path is unaffected.Why
The DG-1 audit (
docs/design/decrementguard-audit.mdsection 4) traced thefinish_filerelease 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+BarrierStatebehindSlotEntry), but until this change the worker'sDecrementGuardstill travelled on theSlotBarrieradapter. Becauseslot_formints a fresh adapter per call, every clone of that adapter kept theArc<SlotData>strong count above 1 across the flusher's unwrap window. Retyping the guard toArc<BarrierState>directly is the structural fix; thedrain.rsspin-then-yield workaround (DG-4 territory) stays in place for now.References
docs/design/dg-2a-option-b-spec.mdsection 2 (split rationale) and section 6 (worker drop body).SlotEntry).Test plan
flush_workers_survives_spurious_wakeup,flush_workers_blocks_until_worker_drops_arc,drain_inflight_drains_all_files,finish_file_calls_flush_workers_internallyall stay greenconcurrent_register_and_dispatch_on_overlapping_filesstress test still passes