Feature: introduce incremental snapshotting#756
Open
desertfury wants to merge 8 commits into
Open
Conversation
Contributor
Author
|
I also ran global_rebuild_gt through the insert-heavy tests to confirm the adapter doesn't fall over under a variety of workloads. And wired the adapter into test_collection across the whole matrix (scalars, connectivity, dimensions, collection sizes). Didnt commit that one |
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.
Motivation
Persisting a large HNSW index with
saveis a stop-the-world operation:the index serves no reads or writes for the entire flush. This PR adds an
interruptible, resumable serialization path and a
global_rebuild_gtadapter that periodically reconstructs and persists the index without
that pause - and without doubling memory.
Resumable serialization
index.hpp/index_dense.hppgain asave_to_stream(output, state&, budget)overload alongside the existing blocking one:
index_serialized_state_t/index_dense_serialized_state_tarecontinuation cursors (stage + position + frozen counts).
budgetnodes/vectors, then returns; pass thesame cursor back to resume. The byte layout is identical to the blocking
save_to_stream, so the file loads with the regularload.global_rebuild.hpp - the orchestrator
global_rebuild_gtwraps a live "primary" index and drives a rebuild insmall budgeted steps, so the index keeps serving traffic throughout:
begin()) into afresh "shadow" peer, reconstructing the HNSW graph from scratch;
save_to_stream;Concurrent-mutation routing:
addalways goes to the primary;removeduring a rebuild is tombstoned and replayed at completion, so the on-disk
snapshot equals the
begin()generation exactly.The idea behind that adapter is described at Chapter 5 of The Design of Dynamic Data Structures book (https://link.springer.com/book/10.1007/BFb0014927)
Memory: no doubling
The shadow needs its own graph, but not a second copy of the vectors.
It is built with
add(..., copy_vector = false), so every shadow nodereferences the primary's stored vector bytes (new
index_dense_gt:: vector_dataaccessor) instead of duplicating them. Peak rebuild overheaddrops from
vectors + graph(~2x) to one graph, and is released atcompletion.
Testing
test_global_rebuild- drives a non-blocking rebuild on a clustered12k x 256d dataset with interleaved add/remove, reloads the persisted
file, and asserts: recall is preserved (1.000 -> 1.000), the shadow
duplicates zero vectors (
memory_stats().vectors_allocated == 0), andthe process RSS sampled across the rebuild grows ~10% - never doubling.