Repository navigation
refactor(index): let the v3 shufflers own their scratch directory - #9265
Merged
Xuanwo merged 6 commits intoOct 23, 2026
Merged
Conversation
…ns-scratch-dir # Conflicts: # rust/lance-index/src/vector/v3/shuffler.rs
The upstream merge widened TwoFileShuffleReader::try_new / try_new_with_preload_limit, but the reader test calls carried over from the merged tests still used the pre-merge arity, breaking the lance-index unit test target. Thread the owned scratch dir (None) through each.
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The reader-call integration defect remains fixed against the updated base. Shufflers and readers retain the scratch-directory guard, removing the caller-held lifetime invariant while preserving caller-owned staging cleanup and index-format semantics.
Xuanwo
approved these changes
Oct 23, 2026
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
The v3 shufflers hold only
output_dir: Path, so whoever creates the shuffle scratch directory has to keep aTempStdDirguard alive for the whole build. #8993 fixed one instance of that going wrong, but the invariant it left behind is a naming convention:let (.., _) = prepare_vector_segment_build(..)compiles, binds nothing, drops the guard at the end of the statement, and the leak is back.#[must_use]does not help, because binding to_counts as a use. Three build paths each kept their own guard alive by hand, and the regression test reaches only one of them.Fixes #9264.
What this changes
IvfShufflerandTwoFileShufflercan now own the directory they shuffle into, the way the legacy shuffler already does withowned_temp_dir. A privateScratchDirpairs the directory with its guard in one constructor, so outside the shuffler module a shuffler cannot be handed a guard for some directory other than the one it writes into.create_owned_ivf_shufflercreates the directory and hands it over;create_ivf_shufflerkeeps its signature for the two call sites that shuffle into a subdirectory of a staging area they clean up themselves.The readers get a clone of the guard as well, not just the shufflers.
IvfIndexBuilderdeclaresshufflerbeforeshuffle_reader, so on drop the reader outlives the shuffler and can be the last thing that still needs the directory. Without that clone, dropping the shuffler first would delete the partition files before the reader reads them.prepare_vector_segment_buildreturns its original 4-tuple again, and the incremental and optimize paths no longer build aTempStdDirof their own. No existing public item oflance-indexchanges signature;create_owned_ivf_shuffleris new and takes notempfiletype, and the builder methods that do are private.Test plan
test_owned_scratch_dir_outlives_the_shuffleris anrstestover both shufflers. Each case drops the shuffler, asserts the directory is still there and reads a partition through the reader, then drops the reader and asserts the directory is gone. Negative control: with the readers' guard clone replaced byNone, both cases fail on the first assertion, including theIvfShufflercase that nothing exercised before.test_shuffle_scratch_dir_is_not_leakedfrom #8993 is unchanged and covers the freshcreate_indexbuild end to end. The incremental, optimize and distributed paths still have no leak test of their own; they now go through the samecreate_owned_ivf_shufflerthat the shuffler-level test pins.Not covered, and worth knowing:
create_shufflerselects between the two shufflers onLANCE_LEGACY_SHUFFLER, which nothing in the repo sets, so that branch itself is still driven only by the default arm.