[dev][RangeIndex] Fix FlagRecovered never cleared on RangeIndex stub after restore#1746
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a RangeIndex recovery/eviction correctness issue where FlagRecovered remained set on restored stubs after checkpoint recovery, causing subsequent eviction cycles to restore from a stale checkpoint snapshot instead of the latest flush.bftree.
Changes:
- Clear
RangeIndexStub.FlagRecoveredinRangeIndexManager.RecreateIndex()after the first post-recovery restore. - Add a regression test covering the “recover → write → flush → evict → restore” second-eviction scenario to ensure post-recovery writes are preserved.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| libs/server/Resp/RangeIndex/RangeIndexManager.Index.cs | Clears FlagRecovered during RIRESTORE stub recreation so later restores choose the flush snapshot. |
| test/Garnet.test/RespRangeIndexTests.cs | Adds an end-to-end regression test reproducing the stale-checkpoint-on-second-eviction bug. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3aad625 to
69212e8
Compare
After server recovery from a checkpoint, MarkRecoveredFromCheckpoint sets FlagRecovered on the RangeIndex stub. However, RecreateIndex (called when the tree is lazily restored) never cleared this flag. This caused RestoreTreeFromFlush to incorrectly pick the stale checkpoint snapshot instead of the fresh flush.bftree on a second eviction cycle, losing all writes made between recovery and the second eviction. Fix: Clear FlagRecovered in RecreateIndex() after setting the new TreeHandle. This is safe because eviction always goes through OnFlush first (which writes a fresh flush.bftree), so any post-restore eviction will have the correct flush snapshot available. Add regression test RIRecoverThenSecondEvictionUsesFlushSnapshotTest that exercises the full scenario: checkpoint -> recover -> restore -> write new data -> flush -> promote -> write more -> evict -> restore again -> assert post-recovery data is present. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
69212e8 to
f0360b9
Compare
badrishc
approved these changes
Apr 30, 2026
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.
Summary
After checkpoint recovery, FlagRecovered is set on RangeIndex stubs but never cleared. On a second eviction cycle, RestoreTreeFromFlush picks the stale checkpoint snapshot instead of the fresh flush.bftree, losing post-recovery writes.
Root Cause
RecreateIndex() only sets TreeHandle — it does not clear FlagRecovered. No other code path clears the flag either.
Scenario:
Fix
Clear FlagRecovered in RecreateIndex() after setting the new TreeHandle. This is safe because Tsavorite always calls OnFlush (which writes a fresh flush.bftree) before eviction, so any post-restore eviction will have the correct flush snapshot available.
Testing