Skip to content

refactor(index): let the v3 shufflers own their scratch directory - #9265

Merged
Xuanwo merged 6 commits into
lance-format:mainfrom
LuciferYang:feat/v3-shuffler-owns-scratch-dir
Oct 23, 2026
Merged

Xuanwo merged 6 commits into
lance-format:mainfrom
LuciferYang:feat/v3-shuffler-owns-scratch-dir

Conversation

@LuciferYang

@LuciferYang LuciferYang commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The v3 shufflers hold only output_dir: Path, so whoever creates the shuffle scratch directory has to keep a TempStdDir guard 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

IvfShuffler and TwoFileShuffler can now own the directory they shuffle into, the way the legacy shuffler already does with owned_temp_dir. A private ScratchDir pairs 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_shuffler creates the directory and hands it over; create_ivf_shuffler keeps 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. IvfIndexBuilder declares shuffler before shuffle_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_build returns its original 4-tuple again, and the incremental and optimize paths no longer build a TempStdDir of their own. No existing public item of lance-index changes signature; create_owned_ivf_shuffler is new and takes no tempfile type, and the builder methods that do are private.

Test plan

test_owned_scratch_dir_outlives_the_shuffler is an rstest over 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 by None, both cases fail on the first assertion, including the IvfShuffler case that nothing exercised before.

test_shuffle_scratch_dir_is_not_leaked from #8993 is unchanged and covers the fresh create_index build end to end. The incremental, optimize and distributed paths still have no leak test of their own; they now go through the same create_owned_ivf_shuffler that the shuffler-level test pins.

Not covered, and worth knowing: create_shuffler selects between the two shufflers on LANCE_LEGACY_SHUFFLER, which nothing in the repo sets, so that branch itself is still driven only by the default arm.

@github-actions github-actions Bot added the A-index Vector index, linalg, tokenizer label Sep 16, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 16, 2026
…ns-scratch-dir

# Conflicts:
#	rust/lance-index/src/vector/v3/shuffler.rs
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 2, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

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.
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 2, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 16, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 16, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 23, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 23, 2026
@Xuanwo
Xuanwo merged commit e80528d into lance-format:main Oct 23, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: let the v3 shufflers own their shuffle scratch directory

2 participants