perf(segment): reuse first vector index file as merge base during compaction#440
Open
JalinWang wants to merge 38 commits into
Open
perf(segment): reuse first vector index file as merge base during compaction#440JalinWang wants to merge 38 commits into
JalinWang wants to merge 38 commits into
Conversation
# Conflicts: # src/db/index/segment/segment_helper.cc
IVF streamers return null from create_provider() until the index is loaded. On the non-reuse merge path the target streamer is empty, so the eager next_id init crashed with SIGSEGV. Fall back to 0 when the provider is null — that is the correct starting id for an empty target.
# Conflicts: # src/db/index/segment/segment_helper.cc
| } | ||
|
|
||
| protected: | ||
| VersionManager::Ptr CreateVersionManager(const CollectionSchema &schema) { |
Collaborator
There was a problem hiding this comment.
有实测过比如hnsw 100w+1w这种case的optimize性能收益吗?
Collaborator
There was a problem hiding this comment.
最好记录好测试结果,并且可以在commit message里面体现吧
Collaborator
Author
There was a problem hiding this comment.
report link:
zvec_segment_indexer_reuse_benchmark.md
Collaborator
There was a problem hiding this comment.
可以直接放到commit message里面,这个link是在个人仓库单独维护的?
Collaborator
There was a problem hiding this comment.
OK,看到commit message里面已经有了
Collaborator
There was a problem hiding this comment.
建议去掉外部link,把test design+result放到commit message里面即可
Collaborator
This reverts commit 9e8d4f2.
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.

Closes #98.
Summary
ReduceVectorIndexalways rebuilt merged vector indexes from scratch during compaction/optimize, even when no filtering was needed and the segments were layout-compatible. This PR adds a fast path that copies the first segment's vector index file as the merge base and only merges the tail segments into it, falling back to a full rebuild when reuse is unsafe.Changes
Reuse path in segment compaction
src/db/index/segment/segment_helper.{h,cc}MergeWithOptionalReuse(output_path, field, source_indexers, filter, concurrency, *merged_indexer)encapsulates the copy-or-rebuild decision. Called by both the unquantized branch and both flat/quantize legs of the quantized branch inReduceVectorIndex.CanReuseFirstIndexergates reuse on:nullptr; not an emptyRowIdFilter)HNSW,HNSW_RABITQ,FLAT} — i.e. streaming-style indexes whoseMergeappends to an in-memory graph.IVF/VAMANArebuild from scratch inMerge(dump-then-reopen) and would silently drop the base file's docs, so they always take the full-rebuild path.index_typeandquantize_typematch the output field'sFileHelper::CopyFile→Open(create_new=false)→Merge(tail_indexers, …). On any copy failure, logs a warning and falls back to the rebuild path.ExecuteCompactTasknow leavesrow_id_filternull when the delete bitmap is empty, so the no-deletes compaction can actually take the reuse path.Append-not-overwrite when merging into a non-empty target
src/core/mixed_reducer/mixed_streamer_reducer.ccreduce()initializesnext_idfromtarget_streamer_->create_(sparse_)provider()->count()when merging into a non-empty target (the reuse case). Previously it started at 0, which would stamp the new docs over the base data.Public accessor
src/db/index/column/vector_column/vector_column_indexer.hfield_schema()getter soCanReuseFirstIndexercan compare the source indexer's schema (index/quantize type) against the output field.Tests
tests/db/index/segment/segment_helper_test.ccSegmentCompactReuseTestfixture; rewrote the merge-reuse cases as parameterized regressions covering:Gains
zvec_segment_indexer_reuse_benchmark.md
References