fix(index): keep the shuffler scratch directory alive for the whole build - #8993
Open
LuciferYang wants to merge 1 commit into
Open
fix(index): keep the shuffler scratch directory alive for the whole build#8993LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
…uild prepare_vector_segment_build created the shuffler's scratch directory as a local TempStdDir and returned only the shuffler, so the guard dropped when the function returned: the directory was removed before the build wrote into it (the writer recreated it) and nothing ever cleaned it up afterwards, leaking one scratch directory per index build. Return the guard alongside the shuffler so callers hold it until the build finishes. The incremental build path already keeps its guard in the enclosing function scope and is unchanged.
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The change restores scratch-directory ownership at the helper boundary and keeps the guard alive through both local and distributed builds, preserving cleanup on success, error, and cancellation. The scoped guard is the appropriate minimal fix; moving ownership into the shuffler and reader types would broaden the contract without improving these caller lifetimes.
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.
Problem
prepare_vector_segment_buildcreates the shuffle scratch directory as a localTempStdDirand returns only the shuffler, which carries just the directory path. The guard drops when the helper returns, so the directory is removed before the build writes into it. The shuffle writer recreates it, and from then on nothing owns it. Every vector index build leaks one scratch directory, and each one holds a shuffled copy of the vector column.Fixes #8992.
What this changes
The helper returns the guard alongside the shuffler, and both callers hold it until the build finishes. The incremental build path and the optimize path already keep their guards in the enclosing function scope and are untouched.
#6980 fixed the same thing for the legacy IVF_HNSW partition staging directory.
Test plan
test_shuffle_scratch_dir_is_not_leakedruns two real index builds in a child process withTMPDIRpointed at an isolated directory, then asserts no scratch directory survives. Negative control: with the guard bound as bare_at one call site, the test reportsleaked 2 scratch directories, one per build. It builds throughcreate_index, so it covers the local path; the distributed path needs precomputed centroids and is not exercised by it.test_prepare_vector_segment_build_keeps_scratch_dir_alivecovers the helper's own contract: it drives the returned shuffler, asserts the shuffle output lands under the returned guard, then drops the guard and asserts the output goes with it.End to end, one index build with
TMPDIRpointed at an empty directory:abcd800cd.tmpXXXXXX/withshuffle_data.lance,shuffle_data.spill,shuffle_offsets.lance,shuffle_offsets.spillcargo test -p lance --lib3382 passed, 4 ignoredcargo clippy --all --tests --benches -- -D warningscleancargo fmt --all --checkclean