Skip to content

fix: spill external-sort runs into one file - #1062

Merged
brawer merged 1 commit into
mainfrom
fix/spill-single-file
Nov 27, 2026
Merged

brawer merged 1 commit into
mainfrom
fix/spill-single-file

Conversation

@brawer

@brawer brawer commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Requested by Sascha · project thread

What failed

The release build fails in cargo auditable test --release --locked:

---- pipeline::edits::spill::tests::sorts_in_memory_and_on_disk stdout ----
Error: failed to open spool file /tmp/.tmpe7mOBf/edits-test-GfgjW2/run-999
Caused by:
    No file descriptors available (os error 24)

Spill (the external sort in make_edits) wrote every sorted run to its own file (run-0, run-1, …) and, during the merge, held one open descriptor per run. With a budget of 1 byte the test writes 1000 runs, which exceeds the container's open-file limit. A large production input could hit the same limit.

Fix

  • All runs of a spill now go into a single temporary file, one lz4 frame after the other; the spill remembers each run's byte range.
  • During the merge, each run reads its own range with positional reads (pread) on one shared File, so a spill holds one descriptor regardless of the number of runs.
  • tables::records gains read_records / write_records for header-less record frames; RecordReader and RecordWriter now use the same code.
  • New test many_runs_share_one_file_descriptor writes 5000 runs and checks the descriptor count via /proc/self/fd.

Testing

  • Reproduced the failure locally with ulimit -n 256 before the fix.
  • After the fix, cargo test --release --locked passes in full (lib + integration, with tippecanoe installed) under ulimit -n 1024.
  • cargo clippy --release --all-targets --locked -- -D warnings and cargo fmt --check are clean.

Generated by Claude Code

The external sort of make_edits wrote each sorted run to its own spool
file and kept one descriptor per run open during the merge. With enough
runs this hits the open-file limit: the release build's container fails
`sorts_in_memory_and_on_disk` (1000 runs) with "No file descriptors
available (os error 24)", and a large production input could do the
same.

Now all runs of a spill go into a single temporary file, one lz4 frame
after the other. During the merge every run reads its own byte range
with positional reads (pread), so a spill holds one descriptor no
matter how many runs it writes. records.rs gains read_records and
write_records for header-less frames of records, which RecordReader
and RecordWriter now share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ttfb2JL29fRPntpK2EgHuM
@brawer brawer self-assigned this Nov 27, 2026
@github-actions github-actions Bot added the bug Something isn't working label Nov 27, 2026
@brawer
brawer merged commit 35adc7a into main Nov 27, 2026
6 checks passed
@brawer
brawer deleted the fix/spill-single-file branch November 27, 2026 18:37
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.

2 participants