Repository navigation
Conversation
Each RefCountedTempFile kept a NamedTempFile—and with it one open file descriptor—for the entire lifetime of the spill file. Operators that retain many spill runs (such as a hash aggregate before its final merge) hold one descriptor per live run and can hit EMFILE (Too many open files) under tight memory limits with the default ulimit -n of 1024. Store TempPath in RefCountedTempFile instead and open the file on demand in append mode in open_writer (read_stream already opens the path on demand). Live spill files then hold no file descriptors, so descriptor usage scales with active writers and readers instead of total live spill files. Removes RefCountedTempFile::inner(&self) -> &NamedTempFile, which is unused in the workspace.
adriangb
marked this pull request as ready for review
November 20, 2026 06:04
adriangb
commented
Nov 20, 2026
| files.push(file); | ||
| } | ||
|
|
||
| let held = open_fd_count().saturating_sub(before); |
Contributor
Author
There was a problem hiding this comment.
what if other tests are opening files?
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.
Which issue does this PR close?
Rationale for this change
Each
RefCountedTempFilecurrently holds anArc<NamedTempFile>, which keeps an open OS file descriptor for the entire lifetime of the spill file even while it sits idle on disk.Under tight memory limits (e.g., 256 MB–512 MB with 16 partitions), operators that accumulate many spill runs—such as a hash aggregate before its final merge—hold one file descriptor per live spill file. On ClickBench Q18 at a 256 MB limit, this reaches ~1,000 live runs and fails with
Too many open files(EMFILE) under the defaultulimit -nof 1024.RefCountedTempFile::read_streamalready opens the file by path on demand. HoldingTempPathinstead ofNamedTempFilemeans live spill files hold no file descriptors, so descriptor usage scales with active open writers and readers rather than total live spill files.What changes are included in this PR?
Arc<TempPath>instead ofArc<NamedTempFile>inRefCountedTempFile(datafusion/execution/src/disk_manager.rs), converting the created file via.into_temp_path().OpenOptions::new().append(true)mode inRefCountedTempFile::open_writer, preserving shared-offset append behavior across multiple writers on the same spill file.RefCountedTempFile::inner(&self) -> &NamedTempFile(unused in the workspace).live_spill_files_hold_no_file_descriptorsverifying that 400 live spill files do not accumulate open file descriptors and still read back and clean up on drop.Are these changes tested?
cargo test -p datafusion-execution --lib(including the newlive_spill_files_hold_no_file_descriptorstest)cargo clippy -p datafusion-execution --all-targets -- -D warningscargo fmt --all -- --checkAre there any user-facing changes?
Breaking public API change:
RefCountedTempFile::inner(&self) -> &NamedTempFileis removed becauseRefCountedTempFileno longer holds an openNamedTempFile. Callers that need the path can useRefCountedTempFile::path(), and callers that need to write or read can use theSpillFiletrait methods.