Prevent dead node accumulation in eviction queue#39
Open
krleonid wants to merge 1 commit into
Open
Conversation
Skip re-insertion into the eviction queue when a block's existing entry is still valid. Previously, every unpin unconditionally re-inserted, creating a dead node for each prior entry. In production with 70K databases this led to 224M queue entries (73% dead), causing Purge to block queries for seconds. The fix tracks whether a block needs queue insertion via an atomic flag: - Set true on first load (from disk) — block has no queue entry yet - Cleared after successful insertion — entry is valid - Re-set if eviction consumes the entry without unloading the block Also fixes TryGetBlockMemory to only check seq_num (not full CanUnload) so that pinned blocks are correctly retained during Purge instead of being discarded as dead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
needs_eviction_queue_insertflag onBlockMemoryTryGetBlockMemoryto only check seq_num (not fullCanUnload) so pinned blocks are retained during PurgeProblem
In production with 70K attached databases, the eviction queue accumulated 224M entries with 163M dead nodes (73%). Every 4096th unpin triggered a Purge that scanned millions of entries, blocking queries for ~5 seconds.
Root cause: every pin/unpin cycle unconditionally re-inserted the block into the queue, creating a dead node for the previous entry. Hot blocks (read frequently, never evicted) generated dead nodes linearly with access count.
Fix
needs_eviction_queue_insertflag: settrueon load from disk (no queue entry exists), cleared after insertion, re-set if eviction consumes entry without unloadingAddToEvictionQueue: early-return when flag is false (entry still valid)IterateUnloadableBlocks: when eviction dequeues a valid entry but can't evict (block pinned), mark block for re-insertion on next unpinTryGetBlockMemory: only check seq_num match, notCanUnload()— pinned blocks are alive (not dead) and should be re-enqueued during PurgeResults (local benchmark)
Same workload (20-column table, repeated reads):
Test plan
🤖 Generated with Claude Code