Repository navigation
refactor(core): save the index rebuilt at open through index_sync - #1809
Merged
Merged
Conversation
) The open-time migration (SQLite has vectors, the index file is empty or gone) saved the rebuilt index with `index.save().ok()`: one attempt, the error dropped. It now goes through `index_sync::persist_rebuilt`: the standard bounded retry, a warning when it still fails, and the open itself is not failed (SQLite holds every vector, the next open rebuilds again). The other three sites named in #1758 already call index_sync (remove_ids and upsert); what they do themselves is take the write lock the module expects its caller to hold, so nothing changes there. Tests: persist_rebuilt saves once, retries a transient failure and gives up after the policy's attempts without failing (FakeIndex), and a store whose index file is gone gets the rebuilt entry written at open, before shutdown.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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.
What
The index that is rebuilt from SQLite at open is now saved through
index_sync::persist_rebuiltinstead ofindex.save().ok(): the standard bounded retry, a warning when it still fails, and the open is not failed.Why
#1758 lists four places that still "lock the index directly" although
index_syncis meant to be the one place for the persist and retry policy. Audit of the four, againstdevelop:consolidate.rs:161(remove_ids),operations/write.rs:493(upsert) andlib.rs:830(remove_from_index,remove_ids) already callindex_sync. What they do themselves is take the write lock, which the module header says its caller holds (&mut impl IndexWriter), the same as every other caller. Nothing to route there, so nothing changes.lib.rs:1151is the real exception: the open-time migration (SQLite has vectors, the index file is empty or gone) calledindex.save().ok(). One attempt, the error dropped. This PR fixes that one.Behaviour change, small and only on failure: a failing save is retried up to the standard 3 attempts (200 ms apart) and logs a warning, where it used to be dropped silently. A save that works behaves as before. If it still fails the open succeeds, as before: SQLite holds every vector and the next open rebuilds the index.
How
index_sync::persist_rebuilt(&mut impl IndexWriter, &SyncPolicy) -> boolwrapspersistand logs instead of returning the error.finish_open_fullcalls it afterindex.build(...).Not changed on purpose: the three lock-poison policies of the other sites differ (
consolidate.rsreturns an error,write.rsreports it in the outcome,remove_from_indexreturns silently). Unifying them is a behaviour change and is left for a decision of its own.Testing
cargo test --workspacepassescargo fmt --all -- --checkpassescargo clippy --workspace --all-targets -- -D warningspassescora review --base origin/develop)The index open path is feature-dependent, so it was also run on the other backends:
cargo check -p uteke-core --no-default-features --features vecq,cargo test -p uteke-core --features "usearch,vecq" --lib vector_engine, and the new store test with--no-default-features --features "onnx,vecq".New tests:
persist_rebuilt_saves_once_when_the_save_works,persist_rebuilt_retries_a_transient_save_failureandpersist_rebuilt_gives_up_after_the_policy_attempts_without_failing, on the existingFakeIndex(the failing-writer adapter the issue asks for).a_missing_index_file_is_rebuilt_and_saved_at_open: a store whose index file is deleted gets it back with the rebuilt entry at open, before any shutdown. The file is created empty when the index is built, so the test compares sizes (0 against 3328 bytes). Checked red with thepersist_rebuiltcall disabled, green with it.Mutation gate on the diff (owner rule 2026-08-19),
cargo mutants -p uteke-core --in-diff: 3 mutants, 2 caught, 1 unviable (does not compile), 0 missed.Related Issues
Closes #1758
Checklist
fix/,feat/,docs/,chore/,refactor/,test/,perf/,security/)develop