Fix vectorset context reuse after checkpoint/recovery metadata skew - #1985
Draft
tiagonapoli wants to merge 1 commit into
Draft
Fix vectorset context reuse after checkpoint/recovery metadata skew#1985tiagonapoli wants to merge 1 commit into
tiagonapoli wants to merge 1 commit into
Conversation
The index-config record (which pins a context id) is written to the store in the create-on-read path BEFORE UpdateContextMetadata flushes the matching in-use bit. A checkpoint taken in that window makes the index durable while the persisted ContextMetadata still reports the context free. On recovery, NextVectorSetContext re-hands-out that context to an unrelated vector set, whose elements then collide on the recovered index's namespace (element records are keyed by context namespace only, no generation tag) - the root of the flaky RecreateIndexesOnRestoreAsync failure (Expected 2 But was 4). Fix: in ResumePostRecovery, for every recovered index-config whose context metadata reports it free, reconcile it back to in-use (using the hash slot recovered from the index record key) so a recovered context is never re-handed-out. Adds a deterministic repro (CreateMetadataSkewRecyclesLiveContextOnRestoreAsync) driven purely by real ops (VADD/VSIM/Save/recover) plus a single timing gate (VectorSet_Interrupt_Before_Create_Metadata_Persist) that throws in the skew window - no synthetic state mutation. Fails without the fix (namespace collision, Expected 0 But was 1), passes with it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 50b7a035-5389-46a7-8423-7806ef1635c3
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.
Problem
Element records in a vector set are keyed by context namespace only (no generation/epoch tag), and context ids are recycled. In the create-on-read path the index-config record — which pins the chosen context id — is written to the store before
UpdateContextMetadataflushes that context's in-use bit.If a checkpoint is taken (or a crash occurs) in that window, the index-config becomes durable while the persisted
ContextMetadatastill reports the context free. On recovery,NextVectorSetContextre-hands-out that context to an unrelated vector set, and the two sets collide on the same namespace. This is the root cause of the flakyRecreateIndexesOnRestoreAsyncfailure (Expected: 2 But was: 4).Fix
In
ResumePostRecovery, for every recovered index-config whose context metadata reports it free, reconcile it back to in-use — using the hash slot recovered from the index record's key. A recovered context can never be re-handed-out, closing the skew window.Test
Adds
CreateMetadataSkewRecyclesLiveContextOnRestoreAsync— a deterministic repro driven purely by real ops (VADD / VSIM / Save / recover) plus a single timing gate (VectorSet_Interrupt_Before_Create_Metadata_Persist) that throws in the skew window. No synthetic state mutation. The gate throws (rather than parks) so the create unwinds and releases its lock/epoch, allowing a foreground checkpoint without deadlock.Expected 0 But was 1— a second vector set surfaces through the recovered context's namespace).Validation
TestFixturevariants).Garnet.test.vectorsetsuite: 167 passed, 2 skipped, 0 failed.