Tighten up Recovery/replay/eviction interaction with sizeTracker, including at shutdown, to fix intermittent Garnet test hangs#1932
Open
TedHartMS wants to merge 8 commits into
Open
Tighten up Recovery/replay/eviction interaction with sizeTracker, including at shutdown, to fix intermittent Garnet test hangs#1932TedHartMS wants to merge 8 commits into
TedHartMS wants to merge 8 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to eliminate intermittent hangs in Garnet/Tsavorite by tightening the interaction between recovery/AOF replay, eviction, and the log size-tracker resizer—especially during shutdown—so background resizing cannot race recovery or touch torn-down resources.
Changes:
- Deferred starting the background size-tracker resizer until after checkpoint recovery completes, to avoid recovery/resizer races (
StoreWrapper.cs). - Hardened allocator shutdown and wait loops by stopping the resizer earlier during
AllocatorBase.Dispose()and bailing out of flush/eviction waits once disposal begins (AllocatorBase.cs). - Extended
LogSizeTrackerwithIsRunningand a retainedresizerTaskto improve eviction decisions when the resizer is not active (LogSizeTracker.cs).
PR metadata (title/description) alignment:
- The description matches the intent and the code changes at a high level, but the current
LogSizeTracker.Stop(wait: true)implementation still has a race/semantic gap that can prevent the intended “wait for resizer exit” guarantee (see stored review comment).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| libs/storage/Tsavorite/cs/src/core/Index/Common/LogSizeTracker.cs | Track resizer task state (IsRunning, resizerTask) and adjust start/stop behavior to avoid shutdown hangs. |
| libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs | Stop/wait for resizer earlier in dispose; add disposed checks to avoid indefinite spin-waits; sync-evict when resizer not running. |
| libs/server/StoreWrapper.cs | Avoid starting the resizer during checkpoint recovery; rely on synchronous eviction pre-resizer-start. |
badrishc
approved these changes
Jul 16, 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.
This pull request introduces important changes to the log size tracking and eviction mechanisms in the Tsavorite storage engine, focusing on improving concurrency safety and preventing hangs during recovery and disposal. The main updates ensure that the background resizer does not interfere with recovery, that resource cleanup is orderly, and that eviction is handled correctly depending on whether the resizer is running.
Concurrency and Recovery Safety:
StoreWrapper.cs,AllocatorBase.cs) [1] [2]disposedfield inAllocatorBaseis nowvolatile, and eviction/flush wait loops checkdisposedto avoid spinning indefinitely during shutdown or disposal. (AllocatorBase.cs) [1] [2] [3] [4]Orderly Shutdown and Resource Management:
Disposemethod inAllocatorBasenow stops the size-tracker resizer and waits for it to exit before releasing resources, ensuring the resizer does not access freed resources and preventing potential race conditions. (AllocatorBase.cs) [1] [2]LogSizeTrackernow tracks the resizer task and provides a robustStop(wait: true)mechanism that waits for the task to complete, even if the task was never started due to a pre-canceled token. (LogSizeTracker.cs) [1] [2] [3]Eviction Logic Improvements:
IssueShiftAddressnow checks if the resizer is running (IsRunning) before deciding whether to evict synchronously, ensuring correct eviction behavior during recovery and normal operation. (AllocatorBase.cs,LogSizeTracker.cs) [1] [2]These changes collectively improve the reliability and correctness of log size management, especially during recovery and shutdown scenarios.