Skip to content

fix: bound raw vector reads when splitting IVF partitions - #9574

Merged
Xuanwo merged 4 commits into
mainfrom
xuanwo/bound-split-reshuffle-memory
Sep 28, 2026
Merged

Xuanwo merged 4 commits into
mainfrom
xuanwo/bound-split-reshuffle-memory

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Sep 25, 2026

Copy link
Copy Markdown
Member

When optimize_indices splits IVF partitions, reshuffle_partitions re-reads the raw vectors of every affected partition. It chunked row ids by ObjectStore::block_size(), a byte count (64 KiB on cloud stores), as a row count, and kept io_parallelism() chunks in flight (64 on cloud stores). A split that touches most of the index therefore held most of the table's raw vectors in memory at once. In production this showed up as an IVF_PQ append that was OOM-killed at a 12 GiB memory limit on every retry, since the retried job repeats the same split.

The re-read now uses the fetch policy the join path already had: each fetch is sized to RAW_VECTOR_FETCH_BYTES (32 MiB) with two fetches in flight, and multivector rows are fetched one at a time and regrouped by measured size. Each fetched batch is sliced across the transform workers instead of admitting one whole batch per worker, so the rows held at once depend on the fetch budget rather than on the number of affected rows or CPUs. The transform also moves from tokio::spawn(...).unwrap() to spawn_cpu, so a panic surfaces as an error.

The new resource test (test_ivf_split_reshuffle_memory_stays_bounded, Linux only) re-reads 512 MiB of vectors through a split with a 64 KiB block size. It fails on main (273 MB tracked peak) and passes here (42 MB) against a 128 MiB ceiling; it takes about 100 s in the ci profile.

Benchmark

Default optimize_indices on 655,360 x 4096-dim f32 vectors (10 GiB) with an IVF_PQ index of 8 partitions and target partition size 8,192, after appending 4,096 rows. The optimize splits the 8 partitions into 83. Each run used a copy of the same dataset opened with a 64 KiB block size, LANCE_IO_THREADS=64, and a 2.73 CPU quota, on c8g.8xlarge (arm64), release build; main (15ca21f) and this branch (builder.rs as of 2c40324) alternated.

Memory limit Variant Peak RSS per run Outcome
none main 22.9 / 25.5 / 27.4 GiB completed
none this PR 1.62 / 1.60 / 1.60 GiB completed
12.24 GiB main - OOM-killed (2/2)
12.24 GiB this PR 1.64 / 1.61 GiB completed (2/2)

Optimize time went from about 201 s to 183-194 s.

@github-actions github-actions Bot added the bug Something isn't working label Sep 25, 2026
@Xuanwo
Xuanwo marked this pull request as ready for review September 26, 2026 06:49

@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 old split path could keep many large fixed-size vector reads in flight. The new fetch budget addresses that OOM path, and the memory and split correctness tests pass.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 26, 2026
@Xuanwo
Xuanwo merged commit 75b4b79 into main Sep 28, 2026
48 of 49 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/bound-split-reshuffle-memory branch September 28, 2026 07:01
Xuanwo added a commit to lancedb/lancedb that referenced this pull request Sep 29, 2026
Updates the Rust workspace dependencies, Cargo lockfile, and Java
`lance-core` to [Lance
v13.0.0-beta.18](https://github.com/lance-format/lance/releases/tag/v13.0.0-beta.18).
It includes lance-format/lance#9574, which bounds the memory an IVF
partition split uses when it re-reads raw vectors during
`optimize_indices`, and lance-format/lance#9582, which keeps the mTLS
REST namespace client on rustls.

Lance's new combined-fields FTS query variant (introduced by
v13.0.0-beta.17) is handled the same way as in #4336: the remote
capability check and Rust/Node bindings accept it, with a regression
test for the remote request payload, and the Python conversion reports
that this query type is not yet supported. This PR supersedes #4336.
LuciferYang added a commit to LuciferYang/lance that referenced this pull request Oct 2, 2026
…eam merge

The upstream merge of lance-format#9574 moved reshuffle_partitions onto the spawn_cpu
CPU-worker pipeline, which resumes a task panic in place and yields
Result<RecordBatch, Error> directly, so there is no JoinError to remap. The
carried-over .map left the stream item type wrong and broke the build. The
shuffle_data path keeps its own mapping, which still applies there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants