Skip to content

feat(engine): DeletePlan, DeletePlanMap, DirTraversalCursor for parallel deterministic delete (#2253, #2254) - #4259

Merged
oferchen merged 2 commits into
masterfrom
feat/delete-plan-and-traversal-2253
May 17, 2026
Merged

oferchen merged 2 commits into
masterfrom
feat/delete-plan-and-traversal-2253

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline (DDP-A3, DDP-A4) described in
docs/design/parallel-deterministic-delete.md (PR #4257). Three new
modules under crates/engine/src/delete/. Pure types; no callers yet
(phase-1 and phase-2 wiring lands in #2255-#2278).

  • plan.rs - DeletePlan (sorted, frozen per-directory work item),
    DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and
    a HardlinkCohortId newtype. sort_by_name() uses upstream's
    f_name_cmp (PR feat(protocol): port upstream f_name_cmp byte-wise name comparator (#2252) #4256) ascending then reverses in place, matching
    delete_in_dir's decrementing loop (generator.c:320).
  • plan_map.rs - DeletePlanMap, the publish-once concurrent
    rendezvous between phase-1 workers and the phase-2 emitter. API:
    insert, take, is_empty, len, contains.
  • traversal.rs - DirTraversalCursor, yields directories in
    upstream's depth-first f_name_cmp-ascending order. Backed by a
    tree built from observed flist segments via observe_segment();
    next_ready() returns the next directory whose parent has been
    emitted (or the root on the first call).

Concurrent-Map Choice

DeletePlanMap is backed by std::sync::Mutex<HashMap<PathBuf, DeletePlan>>.
This is the simplest correct backing store:

  • No new dependency for the engine crate. The workspace's dashmap
    crate is already available (Cargo.toml:203), but pulling it into
    engine enlarges compile time and dependency surface for a module
    that has no measured bottleneck yet.
  • Insert and take are O(1); no I/O happens under the lock.
  • Phase 1 publishes one plan per directory and phase 2 takes it once,
    so contention is short-lived with at most rayon-worker-count
    concurrent writers and one reader.

The bench-driven choice between Mutex<HashMap>, dashmap::DashMap,
and a sharded HashMap is deferred to task DDP-B4 with a code-comment
pointer. The inner type can be swapped without changing the public
surface.

Modules Added

  • crates/engine/src/delete/mod.rs
  • crates/engine/src/delete/plan.rs
  • crates/engine/src/delete/plan_map.rs
  • crates/engine/src/delete/traversal.rs
  • pub mod delete; wired into crates/engine/src/lib.rs.

Test plan

  • CI green on the new branch (fmt+clippy, nextest stable, Windows,
    macOS, Linux musl).
  • plan.rs unit tests:
    • HardlinkCohortId roundtrip.
    • DeleteEntryKind::from_file_type covers every FileType variant.
    • DeleteEntry::new and DeleteEntry::with_cohort set the cohort
      field correctly.
    • DeletePlan::new is empty, unsorted; push resets the sorted
      flag.
    • sort_by_name produces f_name_cmp ascending then reversed
      (descending for plain ASCII).
    • Sort preserves cohort tags and orders mixed kinds by name bytes
      only (no kind-based reordering).
    • ascending_order matches f_name_cmp for Less, Greater,
      Equal.
    • from_extras accepts a pre-built Vec and remains unsorted.
  • plan_map.rs unit tests:
    • new_map_is_empty, with_capacity preallocation.
    • insert then take roundtrips.
    • take of a missing key returns None.
    • Duplicate insert displaces the previous value and returns it.
    • 16 threads x 32 inserts each remain fully retrievable.
    • Concurrent take across 8 threads drains every plan exactly once.
  • traversal.rs unit tests:
    • Empty cursor yields only the root.
    • Single-level children emit in f_name_cmp ascending order.
    • Out-of-order segment observation still yields depth-first
      f_name_cmp order for the (root, a/, a/x/, a/y/, b/) tree.
    • Non-directory children are filtered out.
    • Duplicate observations do not duplicate emissions.
    • Deeper four-level tree emits the full depth-first sequence.
    • Cursor with no observations is exhausted after emitting the root.
    • Unix-only: high-byte basenames sort after ASCII per upstream's
      unsigned byte order.

oferchen added 2 commits May 17, 2026 23:20
…2254)

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline described in docs/design/parallel-deterministic-delete.md
(PR #4257). Three new modules under crates/engine/src/delete/:

- plan.rs: DeletePlan (sorted, frozen per-directory work item),
  DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and a
  HardlinkCohortId newtype. sort_by_name() uses upstream's f_name_cmp
  (PR #4256) ascending then reverses, matching delete_in_dir's loop
  at generator.c:320.
- plan_map.rs: DeletePlanMap, the publish-once concurrent rendezvous
  between phase-1 workers and the phase-2 emitter. Backed by
  Mutex<HashMap> for now; bench-driven choice between Mutex,
  DashMap, and a sharded map is deferred to task DDP-B4 (see code
  comment).
- traversal.rs: DirTraversalCursor, yields directories in upstream's
  depth-first f_name_cmp-ascending order. Tree built from observed
  flist segments via observe_segment(); next_ready() returns the
  next directory whose parent has been emitted.

Pure data structures, no callers; phase-1 and phase-2 wiring lands in
later tasks (#2255-#2278). Unit tests cover plan ordering, concurrent
inserts and takes from 16 threads, out-of-order segment observation,
non-directory filtering, duplicate observations, and high-byte
basename ordering on Unix.
…t_ready

Splits the frame inspection from the mutation so the mutable borrow of
the top frame is released before pushing a new frame or popping the
old one. Functionally equivalent.
@oferchen
oferchen merged commit 795a4d3 into master May 17, 2026
12 of 13 checks passed
@github-actions github-actions Bot added the enhancement New feature or request label May 17, 2026
oferchen added a commit that referenced this pull request May 18, 2026
…lel deterministic delete (#2253, #2254) (#4259)

* feat(engine): DeletePlan, DeletePlanMap, DirTraversalCursor (#2253, #2254)

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline described in docs/design/parallel-deterministic-delete.md
(PR #4257). Three new modules under crates/engine/src/delete/:

- plan.rs: DeletePlan (sorted, frozen per-directory work item),
  DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and a
  HardlinkCohortId newtype. sort_by_name() uses upstream's f_name_cmp
  (PR #4256) ascending then reverses, matching delete_in_dir's loop
  at generator.c:320.
- plan_map.rs: DeletePlanMap, the publish-once concurrent rendezvous
  between phase-1 workers and the phase-2 emitter. Backed by
  Mutex<HashMap> for now; bench-driven choice between Mutex,
  DashMap, and a sharded map is deferred to task DDP-B4 (see code
  comment).
- traversal.rs: DirTraversalCursor, yields directories in upstream's
  depth-first f_name_cmp-ascending order. Tree built from observed
  flist segments via observe_segment(); next_ready() returns the
  next directory whose parent has been emitted.

Pure data structures, no callers; phase-1 and phase-2 wiring lands in
later tasks (#2255-#2278). Unit tests cover plan ordering, concurrent
inserts and takes from 16 threads, out-of-order segment observation,
non-directory filtering, duplicate observations, and high-byte
basename ordering on Unix.

* fix(engine): avoid borrow-checker conflict in DirTraversalCursor::next_ready

Splits the frame inspection from the mutation so the mutable borrow of
the top frame is released before pushing a new frame or popping the
old one. Functionally equivalent.
oferchen added a commit that referenced this pull request May 18, 2026
…lel deterministic delete (#2253, #2254) (#4259)

* feat(engine): DeletePlan, DeletePlanMap, DirTraversalCursor (#2253, #2254)

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline described in docs/design/parallel-deterministic-delete.md
(PR #4257). Three new modules under crates/engine/src/delete/:

- plan.rs: DeletePlan (sorted, frozen per-directory work item),
  DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and a
  HardlinkCohortId newtype. sort_by_name() uses upstream's f_name_cmp
  (PR #4256) ascending then reverses, matching delete_in_dir's loop
  at generator.c:320.
- plan_map.rs: DeletePlanMap, the publish-once concurrent rendezvous
  between phase-1 workers and the phase-2 emitter. Backed by
  Mutex<HashMap> for now; bench-driven choice between Mutex,
  DashMap, and a sharded map is deferred to task DDP-B4 (see code
  comment).
- traversal.rs: DirTraversalCursor, yields directories in upstream's
  depth-first f_name_cmp-ascending order. Tree built from observed
  flist segments via observe_segment(); next_ready() returns the
  next directory whose parent has been emitted.

Pure data structures, no callers; phase-1 and phase-2 wiring lands in
later tasks (#2255-#2278). Unit tests cover plan ordering, concurrent
inserts and takes from 16 threads, out-of-order segment observation,
non-directory filtering, duplicate observations, and high-byte
basename ordering on Unix.

* fix(engine): avoid borrow-checker conflict in DirTraversalCursor::next_ready

Splits the frame inspection from the mutation so the mutable borrow of
the top frame is released before pushing a new frame or popping the
old one. Functionally equivalent.
@oferchen
oferchen deleted the feat/delete-plan-and-traversal-2253 branch May 19, 2026 19:28
oferchen added a commit that referenced this pull request Aug 24, 2026
…lel deterministic delete (#2253, #2254) (#4259)

* feat(engine): DeletePlan, DeletePlanMap, DirTraversalCursor (#2253, #2254)

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline described in docs/design/parallel-deterministic-delete.md
(PR #4257). Three new modules under crates/engine/src/delete/:

- plan.rs: DeletePlan (sorted, frozen per-directory work item),
  DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and a
  HardlinkCohortId newtype. sort_by_name() uses upstream's f_name_cmp
  (PR #4256) ascending then reverses, matching delete_in_dir's loop
  at generator.c:320.
- plan_map.rs: DeletePlanMap, the publish-once concurrent rendezvous
  between phase-1 workers and the phase-2 emitter. Backed by
  Mutex<HashMap> for now; bench-driven choice between Mutex,
  DashMap, and a sharded map is deferred to task DDP-B4 (see code
  comment).
- traversal.rs: DirTraversalCursor, yields directories in upstream's
  depth-first f_name_cmp-ascending order. Tree built from observed
  flist segments via observe_segment(); next_ready() returns the
  next directory whose parent has been emitted.

Pure data structures, no callers; phase-1 and phase-2 wiring lands in
later tasks (#2255-#2278). Unit tests cover plan ordering, concurrent
inserts and takes from 16 threads, out-of-order segment observation,
non-directory filtering, duplicate observations, and high-byte
basename ordering on Unix.

* fix(engine): avoid borrow-checker conflict in DirTraversalCursor::next_ready

Splits the frame inspection from the mutation so the mutable borrow of
the top frame is released before pushing a new frame or popping the
old one. Functionally equivalent.
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