Skip to content

fix(index): clean up IVF shuffler temp dir after index build#6957

Merged
Xuanwo merged 2 commits into
lance-format:mainfrom
geserdugarov:fix-clean-tmp
May 28, 2026
Merged

fix(index): clean up IVF shuffler temp dir after index build#6957
Xuanwo merged 2 commits into
lance-format:mainfrom
geserdugarov:fix-clean-tmp

Conversation

@geserdugarov

Copy link
Copy Markdown
Contributor

Summary

Fixes a temporary directory leak in IVF index shuffling by ensuring auto-created shuffle directories are
cleaned up after index build work is complete.

Changes

  • Keep ownership of auto-created IVF shuffler temp directories with a TempDir guard instead of leaking the
    path.
  • Store the temp-dir guard on IvfShuffler when no caller-provided output directory is used.
  • Keep the guard alive across returned shuffle streams so files are not removed before consumers finish
    reading them.
  • Preserve existing behavior for caller-provided output directories, where cleanup remains the caller’s
    responsibility.
  • Add a regression test that verifies the auto-created temp directory is removed after the shuffler and
    streams are dropped.

Testing

  • cargo test -p lance-index vector::ivf::shuffler::test::test_shuffler_cleans_up_auto_temp_dir

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added the bug Something isn't working label May 27, 2026
@geserdugarov

Copy link
Copy Markdown
Contributor Author

@Xuanwo, @wjones127, hi!
If you don't mind, could you please review this PR?
You've reviewed a lot of PRs related to indexing, so I hope this one is also in your area of interest.

@wjones127 wjones127 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.

Nice work. I appreciate the test. I made an optional suggestion to improve readability. Otherwise, I'm happy to merge this once CI is green.

Comment thread rust/lance-index/src/vector/ivf/shuffler.rs Outdated
@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.45283% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-index/src/vector/ivf/shuffler.rs 92.45% 1 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@geserdugarov

geserdugarov commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I applied the on_drop suggestion. CI run is green.

@Xuanwo
Xuanwo merged commit 0013b74 into lance-format:main May 28, 2026
28 checks passed
@geserdugarov
geserdugarov deleted the fix-clean-tmp branch May 28, 2026 10:22
Xuanwo pushed a commit that referenced this pull request Jul 13, 2026
…6980)

# Summary

Fixes an HNSW-IVF index build bug analogous to #6957, but in the legacy
HNSW partition writer path.

# Changes

- Keeps the `TempStdDir` guard alive for the full
`write_hnsw_quantization_index_partitions` function.
- Prevents scratch `hnsw_part_*` files from disappearing before they are
read back into the final index files.
- No new test added: existing
`index::vector::ivf::tests::test_create_index_nulls` already covers
`IVF_HNSW_PQ` and `IVF_HNSW_SQ` with `IndexFileVersion::Legacy`.

# Testing

- `cargo test -p lance test_create_index_nulls -- --nocapture`
- Result: 10 passed, including the legacy `IVF_HNSW_PQ` and
`IVF_HNSW_SQ` cases.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved reliability when building IVF_HNSW indexes with concurrent
per-partition jobs.
* Ensured temporary scratch directories and intermediate files persist
correctly during in-flight work, and are cleaned up consistently after
errors.
* Improved error propagation so index build failures stop background
work promptly and report late task issues accurately.
* **Tests**
* Added Tokio-based coverage for scratch-directory lifetime, failure
draining/abort behavior, and cleanup under isolated temporary
directories.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

3 participants