Repository navigation
refactor(engine): channel-based drain shutdown for delete emitter (ATU-4 #2381) - #4401
Merged
Merged
Conversation
oferchen
force-pushed
the
feature/atu-4-channel-drain
branch
2 times, most recently
from
May 18, 2026 01:14
664e49e to
9a003da
Compare
…ap at delete emitter (ATU-4 #2381) Convert the cursor handoff in `DeleteContext::into_emitter` from `Arc::try_unwrap(self.cursor)` plus `Mutex::into_inner` to a crossbeam-channel producer/consumer pair. Workers (clones of `Arc<DeleteContext>`) call `observe_segment_for_delete` and `observe_directory`, which enqueue an owned `CursorObservation` onto the producer side. The drain (`into_emitter`) takes `self` by value - by Rust ownership rules every Arc clone has been released by that point - then drops the master sender to close the channel and blocks on `rx.recv()` until it returns `Err`. Each observation is folded into a freshly built `DirTraversalCursor`. No `try_unwrap` on the cursor handle; no `Mutex::into_inner` panic on poison. The plan-map side keeps `Arc::try_unwrap`, now wrapped in a `try_unwrap_or_log` helper that emits a structured `tracing::warn!` with strong/weak counts before returning the original `Arc`. This is the documented transition-era fallback for fragile drain sites that have not yet adopted channel-shutdown handoff (per `docs/architecture/drain-error-recovery.md`). Tests added: - `channel_drain_completes_when_workers_drop_normally` - spawns 8 producer threads, joins them all, asserts the drain finishes without blocking and counts every worker observation. - `channel_drain_completes_when_worker_panics_mid_send` - one worker panics inside `catch_unwind` after sending its observation; the drain still completes and the surviving worker's observation is delivered. For tests and diagnostics that want mid-flight cursor inspection, `cursor_snapshot()` drains the channel, replays the observations into a private cursor, then re-enqueues them so the eventual drain still sees the full set. Three internal tests and one transfer-side integration test now access the cursor through that accessor. `DirTraversalCursor` and its `Frame` derive `Clone` so the snapshot helper can rebuild a private view without changing the original. Closes ATU-4 (#2381).
oferchen
force-pushed
the
feature/atu-4-channel-drain
branch
from
May 18, 2026 01:17
9a003da to
684acea
Compare
6 of 7 tasks
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…ap at delete emitter (ATU-4 #2381) (#4401) Convert the cursor handoff in `DeleteContext::into_emitter` from `Arc::try_unwrap(self.cursor)` plus `Mutex::into_inner` to a crossbeam-channel producer/consumer pair. Workers (clones of `Arc<DeleteContext>`) call `observe_segment_for_delete` and `observe_directory`, which enqueue an owned `CursorObservation` onto the producer side. The drain (`into_emitter`) takes `self` by value - by Rust ownership rules every Arc clone has been released by that point - then drops the master sender to close the channel and blocks on `rx.recv()` until it returns `Err`. Each observation is folded into a freshly built `DirTraversalCursor`. No `try_unwrap` on the cursor handle; no `Mutex::into_inner` panic on poison. The plan-map side keeps `Arc::try_unwrap`, now wrapped in a `try_unwrap_or_log` helper that emits a structured `tracing::warn!` with strong/weak counts before returning the original `Arc`. This is the documented transition-era fallback for fragile drain sites that have not yet adopted channel-shutdown handoff (per `docs/architecture/drain-error-recovery.md`). Tests added: - `channel_drain_completes_when_workers_drop_normally` - spawns 8 producer threads, joins them all, asserts the drain finishes without blocking and counts every worker observation. - `channel_drain_completes_when_worker_panics_mid_send` - one worker panics inside `catch_unwind` after sending its observation; the drain still completes and the surviving worker's observation is delivered. For tests and diagnostics that want mid-flight cursor inspection, `cursor_snapshot()` drains the channel, replays the observations into a private cursor, then re-enqueues them so the eventual drain still sees the full set. Three internal tests and one transfer-side integration test now access the cursor through that accessor. `DirTraversalCursor` and its `Frame` derive `Clone` so the snapshot helper can rebuild a private view without changing the original. Closes ATU-4 (#2381).
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…ap at delete emitter (ATU-4 #2381) (#4401) Convert the cursor handoff in `DeleteContext::into_emitter` from `Arc::try_unwrap(self.cursor)` plus `Mutex::into_inner` to a crossbeam-channel producer/consumer pair. Workers (clones of `Arc<DeleteContext>`) call `observe_segment_for_delete` and `observe_directory`, which enqueue an owned `CursorObservation` onto the producer side. The drain (`into_emitter`) takes `self` by value - by Rust ownership rules every Arc clone has been released by that point - then drops the master sender to close the channel and blocks on `rx.recv()` until it returns `Err`. Each observation is folded into a freshly built `DirTraversalCursor`. No `try_unwrap` on the cursor handle; no `Mutex::into_inner` panic on poison. The plan-map side keeps `Arc::try_unwrap`, now wrapped in a `try_unwrap_or_log` helper that emits a structured `tracing::warn!` with strong/weak counts before returning the original `Arc`. This is the documented transition-era fallback for fragile drain sites that have not yet adopted channel-shutdown handoff (per `docs/architecture/drain-error-recovery.md`). Tests added: - `channel_drain_completes_when_workers_drop_normally` - spawns 8 producer threads, joins them all, asserts the drain finishes without blocking and counts every worker observation. - `channel_drain_completes_when_worker_panics_mid_send` - one worker panics inside `catch_unwind` after sending its observation; the drain still completes and the surviving worker's observation is delivered. For tests and diagnostics that want mid-flight cursor inspection, `cursor_snapshot()` drains the channel, replays the observations into a private cursor, then re-enqueues them so the eventual drain still sees the full set. Three internal tests and one transfer-side integration test now access the cursor through that accessor. `DirTraversalCursor` and its `Frame` derive `Clone` so the snapshot helper can rebuild a private view without changing the original. Closes ATU-4 (#2381).
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…ap at delete emitter (ATU-4 #2381) (#4401) Convert the cursor handoff in `DeleteContext::into_emitter` from `Arc::try_unwrap(self.cursor)` plus `Mutex::into_inner` to a crossbeam-channel producer/consumer pair. Workers (clones of `Arc<DeleteContext>`) call `observe_segment_for_delete` and `observe_directory`, which enqueue an owned `CursorObservation` onto the producer side. The drain (`into_emitter`) takes `self` by value - by Rust ownership rules every Arc clone has been released by that point - then drops the master sender to close the channel and blocks on `rx.recv()` until it returns `Err`. Each observation is folded into a freshly built `DirTraversalCursor`. No `try_unwrap` on the cursor handle; no `Mutex::into_inner` panic on poison. The plan-map side keeps `Arc::try_unwrap`, now wrapped in a `try_unwrap_or_log` helper that emits a structured `tracing::warn!` with strong/weak counts before returning the original `Arc`. This is the documented transition-era fallback for fragile drain sites that have not yet adopted channel-shutdown handoff (per `docs/architecture/drain-error-recovery.md`). Tests added: - `channel_drain_completes_when_workers_drop_normally` - spawns 8 producer threads, joins them all, asserts the drain finishes without blocking and counts every worker observation. - `channel_drain_completes_when_worker_panics_mid_send` - one worker panics inside `catch_unwind` after sending its observation; the drain still completes and the surviving worker's observation is delivered. For tests and diagnostics that want mid-flight cursor inspection, `cursor_snapshot()` drains the channel, replays the observations into a private cursor, then re-enqueues them so the eventual drain still sees the full set. Three internal tests and one transfer-side integration test now access the cursor through that accessor. `DirTraversalCursor` and its `Frame` derive `Clone` so the snapshot helper can rebuild a private view without changing the original. Closes ATU-4 (#2381).
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
Arc::try_unwrapfor the cursor handoff inDeleteContext::into_emitterwith a crossbeam-channel producer/consumer pair. Workers (clones ofArc<DeleteContext>) enqueue cursor observations; the drain takesselfby value, drops the master sender, and blocks onrx.recv() -> Errto assemble an ownedDirTraversalCursorwithout ever callingtry_unwrapon a shared handle.crates/engine/src/delete/context.rs::tests:channel_drain_completes_when_workers_drop_normally- 8 producer threads, all joined; drain finishes without blocking and counts every observation.channel_drain_completes_when_worker_panics_mid_send- one worker panics insidecatch_unwindafter enqueueing; the drain still completes and the surviving worker's observation is delivered.try_unwrap_or_log(with structuredtracing::warn!carryingstrong_count/weak_count/kind); the plan-map side still routes through it as the documented transition-era fallback for fragile drain sites.DeleteContext::cursor_snapshot()for tests and diagnostics that need mid-flight cursor inspection; it drains and re-enqueues observations so the eventual drain still sees the full set. Existing callers that touched the oldpub cursor: Arc<Mutex<...>>field are updated to use the accessor.Test plan
cargo fmt --allclean (whitespace + line lengths verified manually; full fmt run reserved for CI per project policy)pub cursor->pub fn cursor_snapshot(); the four call sites that previously accessed the field directly (one intransfer, three in-file tests) now use the accessorcrossbeam-channelworkspace depunsafe, no#[allow(...)]clippy waivers, no em-dashesCloses ATU-4 (#2381).