Skip to content

feat(engine): wire SpillableReorderBuffer with bounded-memory threshold (#1884) - #4299

Closed
oferchen wants to merge 1 commit into
masterfrom
feat/wire-spillable-reorder-buffer-1884
Closed

oferchen wants to merge 1 commit into
masterfrom
feat/wire-spillable-reorder-buffer-1884

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds ConcurrentDeltaConfig with an opt-in spill_threshold_bytes knob and a new DeltaConsumer::spawn_with_config constructor that swaps the bare ReorderBuffer for the existing SpillableReorderBuffer when the threshold is set.
  • Replaces the legacy force_insert deadlock-breaker fallback with a proper spill: capacity pressure now displaces the highest-sequence items to a tempfile (SpooledTempFile by default, with an explicit spill_dir override) instead of doubling the ring forever.
  • Exposes spill activity through an AtomicU64 accessible via DeltaConsumer::stats() -> DeltaConsumerStats { spill_events }. Spill I/O failures map to DeltaResult::failed, which the receiver already translates to upstream exit code 11 (FileIo).

The default path (spawn, spawn_bypass, and spawn_with_config(.., ConcurrentDeltaConfig::default())) is bit-for-bit identical to the prior behaviour. The wire protocol is unchanged - the spill layer is strictly receiver-local memory management.

Test plan

  • Synthetic 1000-item / 16 KiB-budget adversarial drive: spillable_consumer_preserves_order_under_pressure verifies in-order delivery and spill_events > 0.
  • Byte-for-byte parity vs the non-spilling baseline: spillable_consumer_matches_bare_output_byte_for_byte encodes each delivered DeltaResult via SpillCodec and asserts identical payloads against the bare-ReorderBuffer baseline.
  • Default-off path: spawn_with_config_off_matches_spawn and stats_zero_when_spill_disabled confirm spawn_with_config(.., ConcurrentDeltaConfig::off()) matches spawn(..) exactly and reports zero spill events.
  • ConcurrentDeltaConfig unit tests cover default, off, with_spill_threshold, with_spill_dir, and spill_enabled.
  • cargo fmt --all clean.

…ld (#1884)

Adds ConcurrentDeltaConfig with an opt-in spill_threshold_bytes knob so
the delta consumer can swap its bare ReorderBuffer for the existing
SpillableReorderBuffer. When set, the reorder thread keeps the in-memory
ring footprint under the configured byte budget by serialising the
oldest (highest-sequence) buffered items to a tempfile; the legacy
force_insert deadlock breaker now drives a spill rather than unbounded
ring growth.

Spill activity is published via a lock-free AtomicU64 surfaced through
DeltaConsumer::stats() (DeltaConsumerStats). Spill I/O failures map to
a DeltaResult::failed so the receiver aborts with rsync exit code 11.

Tests cover the 1000-item adversarial workload at a 16 KiB budget
(spill_events > 0, order preserved), a byte-for-byte parity check
against the non-spilling baseline using the SpillCodec encoding, and
the default-off path. Wire output is unchanged; the spill layer is
strictly receiver-local.
@oferchen

Copy link
Copy Markdown
Owner Author

Closing due to unresolvable merge conflicts after drain instrumentation landed. Re-doing fresh on top of current master.

@oferchen oferchen closed this May 17, 2026
oferchen added a commit that referenced this pull request May 17, 2026
…apply (#4319)

Wires the existing SpillableReorderBuffer into DeltaConsumer behind a new
opt-in ConcurrentDeltaConfig, and lands the parallel receive-side delta
apply scaffold behind the parallel-receive-delta cargo feature.

SpillableReorderBuffer wiring (#1884)
- New ConcurrentDeltaConfig { spill_threshold_bytes, spill_dir } selects
  between the bare ReorderBuffer (default, behaviour unchanged) and the
  bounded-memory SpillableReorderBuffer when a threshold is supplied.
- DeltaConsumer::spawn_with_config dispatches via a ReorderMode enum so
  spawn / spawn_bypass / spawn_with_config share one inner loop entry.
- DeltaConsumerStats surfaces the cumulative spill_events counter via a
  lock-free AtomicU64 published by the reorder thread.
- Spill backend construction or I/O failures map to DeltaResult::failed
  for the offending sequence so the receiver maps to upstream exit code
  11 (FileIo) and aborts. Existing histogram/metrics machinery on the
  bare path is preserved verbatim.

Parallel receive delta apply (#1368)
- New parallel-receive-delta feature on engine (forwarded from transfer).
  Default off so production receivers continue to drive the sequential
  apply loop in receiver/transfer.rs.
- engine::concurrent_delta::parallel_apply adds DeltaChunk and
  ParallelDeltaApplier. Per-file Mutex serialises destination writes,
  per-file ReorderBuffer replays chunks in submission order, and
  rayon::join / par_iter fans the verify step across the rayon pool
  while keeping per-file byte order exact.
- ReceiverContext::enable_parallel_receive_delta installs the existing
  ParallelDeltaPipeline only when the feature is compiled in, leaving
  the default receiver loop untouched.

Re-exports the union of ConcurrentDeltaConfig, DeltaConsumerStats, and
(feature-gated) DeltaChunk / ParallelDeltaApplier from
crates/engine/src/concurrent_delta/mod.rs alongside the existing
HistogramStats, ReorderMetrics, and ReorderBuffer surface.

Tests
- spillable_consumer_preserves_order_under_pressure drives 1000 items
  through a 1 KiB budget with a deliberately delayed head-of-line item
  and asserts both in-order delivery and spill_events > 0.
- spillable_consumer_matches_bare_output_byte_for_byte compares spill
  vs bare paths via SpillCodec encoding.
- spawn_with_config_off_matches_spawn and stats_zero_when_spill_disabled
  pin the default-off invariants.
- parallel_apply: in-order, shuffled, and batched byte-equality tests
  plus a proptest over random chunk sizes / deterministic permutations.

Replaces the conflict-stalled PRs #4299 and #4300 with a single
combined change on top of current master.

Closes #1884
Closes #1368
@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
…apply (#4319)

Wires the existing SpillableReorderBuffer into DeltaConsumer behind a new
opt-in ConcurrentDeltaConfig, and lands the parallel receive-side delta
apply scaffold behind the parallel-receive-delta cargo feature.

SpillableReorderBuffer wiring (#1884)
- New ConcurrentDeltaConfig { spill_threshold_bytes, spill_dir } selects
  between the bare ReorderBuffer (default, behaviour unchanged) and the
  bounded-memory SpillableReorderBuffer when a threshold is supplied.
- DeltaConsumer::spawn_with_config dispatches via a ReorderMode enum so
  spawn / spawn_bypass / spawn_with_config share one inner loop entry.
- DeltaConsumerStats surfaces the cumulative spill_events counter via a
  lock-free AtomicU64 published by the reorder thread.
- Spill backend construction or I/O failures map to DeltaResult::failed
  for the offending sequence so the receiver maps to upstream exit code
  11 (FileIo) and aborts. Existing histogram/metrics machinery on the
  bare path is preserved verbatim.

Parallel receive delta apply (#1368)
- New parallel-receive-delta feature on engine (forwarded from transfer).
  Default off so production receivers continue to drive the sequential
  apply loop in receiver/transfer.rs.
- engine::concurrent_delta::parallel_apply adds DeltaChunk and
  ParallelDeltaApplier. Per-file Mutex serialises destination writes,
  per-file ReorderBuffer replays chunks in submission order, and
  rayon::join / par_iter fans the verify step across the rayon pool
  while keeping per-file byte order exact.
- ReceiverContext::enable_parallel_receive_delta installs the existing
  ParallelDeltaPipeline only when the feature is compiled in, leaving
  the default receiver loop untouched.

Re-exports the union of ConcurrentDeltaConfig, DeltaConsumerStats, and
(feature-gated) DeltaChunk / ParallelDeltaApplier from
crates/engine/src/concurrent_delta/mod.rs alongside the existing
HistogramStats, ReorderMetrics, and ReorderBuffer surface.

Tests
- spillable_consumer_preserves_order_under_pressure drives 1000 items
  through a 1 KiB budget with a deliberately delayed head-of-line item
  and asserts both in-order delivery and spill_events > 0.
- spillable_consumer_matches_bare_output_byte_for_byte compares spill
  vs bare paths via SpillCodec encoding.
- spawn_with_config_off_matches_spawn and stats_zero_when_spill_disabled
  pin the default-off invariants.
- parallel_apply: in-order, shuffled, and batched byte-equality tests
  plus a proptest over random chunk sizes / deterministic permutations.

Replaces the conflict-stalled PRs #4299 and #4300 with a single
combined change on top of current master.

Closes #1884
Closes #1368
oferchen added a commit that referenced this pull request May 18, 2026
…apply (#4319)

Wires the existing SpillableReorderBuffer into DeltaConsumer behind a new
opt-in ConcurrentDeltaConfig, and lands the parallel receive-side delta
apply scaffold behind the parallel-receive-delta cargo feature.

SpillableReorderBuffer wiring (#1884)
- New ConcurrentDeltaConfig { spill_threshold_bytes, spill_dir } selects
  between the bare ReorderBuffer (default, behaviour unchanged) and the
  bounded-memory SpillableReorderBuffer when a threshold is supplied.
- DeltaConsumer::spawn_with_config dispatches via a ReorderMode enum so
  spawn / spawn_bypass / spawn_with_config share one inner loop entry.
- DeltaConsumerStats surfaces the cumulative spill_events counter via a
  lock-free AtomicU64 published by the reorder thread.
- Spill backend construction or I/O failures map to DeltaResult::failed
  for the offending sequence so the receiver maps to upstream exit code
  11 (FileIo) and aborts. Existing histogram/metrics machinery on the
  bare path is preserved verbatim.

Parallel receive delta apply (#1368)
- New parallel-receive-delta feature on engine (forwarded from transfer).
  Default off so production receivers continue to drive the sequential
  apply loop in receiver/transfer.rs.
- engine::concurrent_delta::parallel_apply adds DeltaChunk and
  ParallelDeltaApplier. Per-file Mutex serialises destination writes,
  per-file ReorderBuffer replays chunks in submission order, and
  rayon::join / par_iter fans the verify step across the rayon pool
  while keeping per-file byte order exact.
- ReceiverContext::enable_parallel_receive_delta installs the existing
  ParallelDeltaPipeline only when the feature is compiled in, leaving
  the default receiver loop untouched.

Re-exports the union of ConcurrentDeltaConfig, DeltaConsumerStats, and
(feature-gated) DeltaChunk / ParallelDeltaApplier from
crates/engine/src/concurrent_delta/mod.rs alongside the existing
HistogramStats, ReorderMetrics, and ReorderBuffer surface.

Tests
- spillable_consumer_preserves_order_under_pressure drives 1000 items
  through a 1 KiB budget with a deliberately delayed head-of-line item
  and asserts both in-order delivery and spill_events > 0.
- spillable_consumer_matches_bare_output_byte_for_byte compares spill
  vs bare paths via SpillCodec encoding.
- spawn_with_config_off_matches_spawn and stats_zero_when_spill_disabled
  pin the default-off invariants.
- parallel_apply: in-order, shuffled, and batched byte-equality tests
  plus a proptest over random chunk sizes / deterministic permutations.

Replaces the conflict-stalled PRs #4299 and #4300 with a single
combined change on top of current master.

Closes #1884
Closes #1368
@oferchen
oferchen deleted the feat/wire-spillable-reorder-buffer-1884 branch May 19, 2026 19:29
oferchen added a commit that referenced this pull request Aug 24, 2026
…apply (#4319)

Wires the existing SpillableReorderBuffer into DeltaConsumer behind a new
opt-in ConcurrentDeltaConfig, and lands the parallel receive-side delta
apply scaffold behind the parallel-receive-delta cargo feature.

SpillableReorderBuffer wiring (#1884)
- New ConcurrentDeltaConfig { spill_threshold_bytes, spill_dir } selects
  between the bare ReorderBuffer (default, behaviour unchanged) and the
  bounded-memory SpillableReorderBuffer when a threshold is supplied.
- DeltaConsumer::spawn_with_config dispatches via a ReorderMode enum so
  spawn / spawn_bypass / spawn_with_config share one inner loop entry.
- DeltaConsumerStats surfaces the cumulative spill_events counter via a
  lock-free AtomicU64 published by the reorder thread.
- Spill backend construction or I/O failures map to DeltaResult::failed
  for the offending sequence so the receiver maps to upstream exit code
  11 (FileIo) and aborts. Existing histogram/metrics machinery on the
  bare path is preserved verbatim.

Parallel receive delta apply (#1368)
- New parallel-receive-delta feature on engine (forwarded from transfer).
  Default off so production receivers continue to drive the sequential
  apply loop in receiver/transfer.rs.
- engine::concurrent_delta::parallel_apply adds DeltaChunk and
  ParallelDeltaApplier. Per-file Mutex serialises destination writes,
  per-file ReorderBuffer replays chunks in submission order, and
  rayon::join / par_iter fans the verify step across the rayon pool
  while keeping per-file byte order exact.
- ReceiverContext::enable_parallel_receive_delta installs the existing
  ParallelDeltaPipeline only when the feature is compiled in, leaving
  the default receiver loop untouched.

Re-exports the union of ConcurrentDeltaConfig, DeltaConsumerStats, and
(feature-gated) DeltaChunk / ParallelDeltaApplier from
crates/engine/src/concurrent_delta/mod.rs alongside the existing
HistogramStats, ReorderMetrics, and ReorderBuffer surface.

Tests
- spillable_consumer_preserves_order_under_pressure drives 1000 items
  through a 1 KiB budget with a deliberately delayed head-of-line item
  and asserts both in-order delivery and spill_events > 0.
- spillable_consumer_matches_bare_output_byte_for_byte compares spill
  vs bare paths via SpillCodec encoding.
- spawn_with_config_off_matches_spawn and stats_zero_when_spill_disabled
  pin the default-off invariants.
- parallel_apply: in-order, shuffled, and batched byte-equality tests
  plus a proptest over random chunk sizes / deterministic permutations.

Replaces the conflict-stalled PRs #4299 and #4300 with a single
combined change on top of current master.

Closes #1884
Closes #1368
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