Skip to content

fix(engine): harden reorder spill against ENOSPC and temp-dir vanish (#2247) - #4158

Merged
oferchen merged 3 commits into
masterfrom
fix/reorder-spill-hardening-2247
May 16, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/reorder-spill-hardening-2247

Conversation

@oferchen

@oferchen oferchen commented May 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

SpillableReorderBuffer panicked on every disk failure path: ENOSPC
during the spill write, a missing spill file at reload time, and short
writes all turned heavy-transfer faults into process crashes that
downstream consumers could neither catch nor map to an rsync exit code.

This change introduces a typed SpillError (capacity vs I/O) and
threads Result through insert, force_insert, next_in_order,
and drain_ready. Spill failures re-insert the offending item and
surface the error so callers shut down cleanly with exit 11
(FileIo), matching upstream rsync's I/O-failure semantics.

A new with_spill_dir constructor lets callers point the spill file
at an explicit directory. If that directory disappears mid-transfer
(operator cleanup, tmpfs eviction, container restart) the buffer
attempts a single create_dir_all recovery and retries the write
once - but only when nothing has been spilled yet. With prior items
already on the (now-missing) disk, recovery would silently lose them,
so the NotFound error is surfaced instead.

Closes #2247.

What this fix handles

  • ENOSPC during spill write - codec / write_all errors now
    propagate up as SpillError::Io with is_out_of_space() honouring
    ErrorKind::StorageFull. The just-spilled item is re-inserted so
    the caller can shut down without dropping it.
  • Temp directory vanishes before first spill - one
    create_dir_all retry, then the original spill is repeated. The
    dir_recreate_events counter records the recovery.
  • Temp directory vanishes after prior spills - recovery would
    lose unrecoverable items, so the NotFound error is surfaced.
  • Partial writes - the std Write::write_all contract surfaces
    WriteZero rather than dropping bytes; the spill record is encoded
    to an in-memory buffer first so codec failures never leave a
    half-written record on disk.
  • Records exceeding u32::MAX - explicit InvalidData error
    instead of silent truncation.

Tests

All in crates/engine/src/concurrent_delta/spill.rs:

  • enospc_during_spill_propagates_as_io_error - injects
    ErrorKind::StorageFull via a codec and asserts the buffer
    surfaces SpillError::Io with is_out_of_space() == true.
  • partial_write_surfaces_as_write_zero - a writer that takes one
    byte then returns zero confirms the write_all contract surfaces
    WriteZero.
  • temp_dir_vanish_recreates_when_no_prior_spills - removes the
    spill directory before the first spill, then asserts exactly one
    recreate event and successful continuation.
  • temp_dir_vanish_after_prior_spills_returns_error - removes the
    directory after a spill has landed, asserts the next spill returns
    SpillError::Io and does not increment the recreate counter.
  • dir_recreate_failure_surfaces_io_error - points the spill dir at
    a path whose parent is a regular file; create_dir_all fails and
    the error surfaces without panicking.
  • directory_backed_spill_round_trip - the directory backend yields
    byte-for-byte the same delivery order as the spooled backend.
  • spill_error_display_and_source - covers the Display and
    std::error::Error::source impls.

The pre-existing happy-path tests were updated only where the new
Result-returning signatures required (unwrap or .expect); their
assertions are unchanged.

Test plan

  • cargo fmt --all -- --check clean
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings clean
  • cargo nextest run -p engine -E 'test(spill)' all green in CI

oferchen added 2 commits May 16, 2026 19:07
Previously `SpillableReorderBuffer` panicked on every disk failure path:
ENOSPC during the spill write, a missing spill file at reload time, and
short-write fallouts all translated heavy-transfer faults into process
crashes that downstream consumers could neither catch nor map to an
rsync exit code.

This change introduces a typed `SpillError` (capacity vs I/O) and
threads `Result` through `insert`, `force_insert`, `next_in_order`, and
`drain_ready`. Failed spill writes now return the I/O error and re-insert
the offending item so callers can shut down cleanly with exit 11.

The implementation also gains an opt-in `with_spill_dir` constructor.
When the explicit directory disappears mid-transfer (operator cleanup,
tmpfs eviction, container restart), the buffer detects the `NotFound`
error, performs a single `create_dir_all` recovery, and retries the
write once before surfacing the failure.

New tests cover:
- ENOSPC injected through the codec, asserting `SpillError::Io` with
  `ErrorKind::StorageFull` and `is_out_of_space()` true.
- Partial-write via a `OneByteWriter` confirming the std `write_all`
  contract surfaces `WriteZero` rather than silently dropping bytes.
- Removing the spill directory mid-test, then asserting the next spill
  recreates it once (`dir_recreate_events` increments, dir exists).
- `create_dir_all` failure when the parent is a regular file - error
  surfaces without panicking.
- A round-trip on the directory-backed flavour to confirm the happy
  path stays byte-for-byte equivalent to the spooled default.

Success-path semantics are unchanged. All pre-existing tests adapt
trivially to the new `Result`-returning signatures.
Recovery via `create_dir_all` is only safe when nothing has been spilled
yet. With prior items present on the (now-missing) disk a recreate
silently loses them; the transfer would continue with a corrupted
delivery stream.

Return the underlying `NotFound` error in that case so the caller maps
it to exit 11 and aborts cleanly. The recoverable "vanish before first
spill" path still recreates the directory once and resumes.

Split the existing test into two cases (pre-spill recreate succeeds;
post-spill vanish surfaces an error and does not increment the
recreate counter).
@github-actions github-actions Bot added the bug Something isn't working label May 16, 2026
@oferchen
oferchen merged commit e52c1c6 into master May 16, 2026
40 checks passed
@oferchen
oferchen deleted the fix/reorder-spill-hardening-2247 branch May 16, 2026 16:52
oferchen added a commit that referenced this pull request May 18, 2026
…2247) (#4158)

* fix(engine): harden reorder spill against ENOSPC and temp-dir vanish

Previously `SpillableReorderBuffer` panicked on every disk failure path:
ENOSPC during the spill write, a missing spill file at reload time, and
short-write fallouts all translated heavy-transfer faults into process
crashes that downstream consumers could neither catch nor map to an
rsync exit code.

This change introduces a typed `SpillError` (capacity vs I/O) and
threads `Result` through `insert`, `force_insert`, `next_in_order`, and
`drain_ready`. Failed spill writes now return the I/O error and re-insert
the offending item so callers can shut down cleanly with exit 11.

The implementation also gains an opt-in `with_spill_dir` constructor.
When the explicit directory disappears mid-transfer (operator cleanup,
tmpfs eviction, container restart), the buffer detects the `NotFound`
error, performs a single `create_dir_all` recovery, and retries the
write once before surfacing the failure.

New tests cover:
- ENOSPC injected through the codec, asserting `SpillError::Io` with
  `ErrorKind::StorageFull` and `is_out_of_space()` true.
- Partial-write via a `OneByteWriter` confirming the std `write_all`
  contract surfaces `WriteZero` rather than silently dropping bytes.
- Removing the spill directory mid-test, then asserting the next spill
  recreates it once (`dir_recreate_events` increments, dir exists).
- `create_dir_all` failure when the parent is a regular file - error
  surfaces without panicking.
- A round-trip on the directory-backed flavour to confirm the happy
  path stays byte-for-byte equivalent to the spooled default.

Success-path semantics are unchanged. All pre-existing tests adapt
trivially to the new `Result`-returning signatures.

* fix(engine): refuse silent data loss on temp-dir vanish after spills

Recovery via `create_dir_all` is only safe when nothing has been spilled
yet. With prior items present on the (now-missing) disk a recreate
silently loses them; the transfer would continue with a corrupted
delivery stream.

Return the underlying `NotFound` error in that case so the caller maps
it to exit 11 and aborts cleanly. The recoverable "vanish before first
spill" path still recreates the directory once and resumes.

Split the existing test into two cases (pre-spill recreate succeeds;
post-spill vanish surfaces an error and does not increment the
recreate counter).

* fix(engine): drop unused dir field from SpillBackend::Directory
oferchen added a commit that referenced this pull request May 18, 2026
…2247) (#4158)

* fix(engine): harden reorder spill against ENOSPC and temp-dir vanish

Previously `SpillableReorderBuffer` panicked on every disk failure path:
ENOSPC during the spill write, a missing spill file at reload time, and
short-write fallouts all translated heavy-transfer faults into process
crashes that downstream consumers could neither catch nor map to an
rsync exit code.

This change introduces a typed `SpillError` (capacity vs I/O) and
threads `Result` through `insert`, `force_insert`, `next_in_order`, and
`drain_ready`. Failed spill writes now return the I/O error and re-insert
the offending item so callers can shut down cleanly with exit 11.

The implementation also gains an opt-in `with_spill_dir` constructor.
When the explicit directory disappears mid-transfer (operator cleanup,
tmpfs eviction, container restart), the buffer detects the `NotFound`
error, performs a single `create_dir_all` recovery, and retries the
write once before surfacing the failure.

New tests cover:
- ENOSPC injected through the codec, asserting `SpillError::Io` with
  `ErrorKind::StorageFull` and `is_out_of_space()` true.
- Partial-write via a `OneByteWriter` confirming the std `write_all`
  contract surfaces `WriteZero` rather than silently dropping bytes.
- Removing the spill directory mid-test, then asserting the next spill
  recreates it once (`dir_recreate_events` increments, dir exists).
- `create_dir_all` failure when the parent is a regular file - error
  surfaces without panicking.
- A round-trip on the directory-backed flavour to confirm the happy
  path stays byte-for-byte equivalent to the spooled default.

Success-path semantics are unchanged. All pre-existing tests adapt
trivially to the new `Result`-returning signatures.

* fix(engine): refuse silent data loss on temp-dir vanish after spills

Recovery via `create_dir_all` is only safe when nothing has been spilled
yet. With prior items present on the (now-missing) disk a recreate
silently loses them; the transfer would continue with a corrupted
delivery stream.

Return the underlying `NotFound` error in that case so the caller maps
it to exit 11 and aborts cleanly. The recoverable "vanish before first
spill" path still recreates the directory once and resumes.

Split the existing test into two cases (pre-spill recreate succeeds;
post-spill vanish surfaces an error and does not increment the
recreate counter).

* fix(engine): drop unused dir field from SpillBackend::Directory
oferchen added a commit that referenced this pull request Aug 24, 2026
…2247) (#4158)

* fix(engine): harden reorder spill against ENOSPC and temp-dir vanish

Previously `SpillableReorderBuffer` panicked on every disk failure path:
ENOSPC during the spill write, a missing spill file at reload time, and
short-write fallouts all translated heavy-transfer faults into process
crashes that downstream consumers could neither catch nor map to an
rsync exit code.

This change introduces a typed `SpillError` (capacity vs I/O) and
threads `Result` through `insert`, `force_insert`, `next_in_order`, and
`drain_ready`. Failed spill writes now return the I/O error and re-insert
the offending item so callers can shut down cleanly with exit 11.

The implementation also gains an opt-in `with_spill_dir` constructor.
When the explicit directory disappears mid-transfer (operator cleanup,
tmpfs eviction, container restart), the buffer detects the `NotFound`
error, performs a single `create_dir_all` recovery, and retries the
write once before surfacing the failure.

New tests cover:
- ENOSPC injected through the codec, asserting `SpillError::Io` with
  `ErrorKind::StorageFull` and `is_out_of_space()` true.
- Partial-write via a `OneByteWriter` confirming the std `write_all`
  contract surfaces `WriteZero` rather than silently dropping bytes.
- Removing the spill directory mid-test, then asserting the next spill
  recreates it once (`dir_recreate_events` increments, dir exists).
- `create_dir_all` failure when the parent is a regular file - error
  surfaces without panicking.
- A round-trip on the directory-backed flavour to confirm the happy
  path stays byte-for-byte equivalent to the spooled default.

Success-path semantics are unchanged. All pre-existing tests adapt
trivially to the new `Result`-returning signatures.

* fix(engine): refuse silent data loss on temp-dir vanish after spills

Recovery via `create_dir_all` is only safe when nothing has been spilled
yet. With prior items present on the (now-missing) disk a recreate
silently loses them; the transfer would continue with a corrupted
delivery stream.

Return the underlying `NotFound` error in that case so the caller maps
it to exit 11 and aborts cleanly. The recoverable "vanish before first
spill" path still recreates the directory once and resumes.

Split the existing test into two cases (pre-spill recreate succeeds;
post-spill vanish surfaces an error and does not increment the
recreate counter).

* fix(engine): drop unused dir field from SpillBackend::Directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant