Skip to content

Fix eviction queue purge correctness#51

Open
krleonid wants to merge 9 commits into
artjom/backport-metricsfrom
fix/eviction-queue-purge-backport
Open

Fix eviction queue purge correctness#51
krleonid wants to merge 9 commits into
artjom/backport-metricsfrom
fix/eviction-queue-purge-backport

Conversation

@krleonid
Copy link
Copy Markdown
Owner

Summary

  • Fix dead-node under-counting when BlockMemory is destroyed after eviction
  • Fix pinned/current nodes being misclassified as dead during purge
  • Fix moodycamel sub-queue churn causing purge loop to make no progress
  • Add ever_in_eviction_queue flag for accurate dead-node accounting
  • Add regression tests and concurrent stress test

Test plan

  • Buffer pool C++ tests pass (6/6, 36 assertions)
  • Eviction queue underflow slow test passes (4806 assertions)
  • Background purge benchmark shows ~10% improvement

🤖 Generated with Claude Code

krleonid and others added 4 commits May 17, 2026 09:03
…ue churn

Three related bugs in the buffer pool's eviction queue purge path
caused dead nodes to accumulate, alive but pinned nodes to be lost,
and the multi-iteration purge loop to make no real progress.

1. Dead increment skipped when buffer was already null
2. Pinned/current nodes were classified as dead during purge
3. Multi-iteration purge churned the purge thread's own moodycamel sub-queue

Also adds regression tests and a concurrent stress test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eue churn

Replace the alive_nodes_to_reenqueue vector approach with moodycamel
consumer/producer tokens. The consumer token progresses sequentially
through sub-queues, while alive nodes are re-enqueued via a dedicated
producer token whose sub-queue sits behind the consumer position.
This prevents re-processing the same alive nodes on subsequent iterations
without starving the eviction path (nodes stay in the queue, visible to
EvictBlocks).

Also adds background_queue_purge setting and fixes memory_limit syntax
for v1.5-stable compatibility in the stress test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…in test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread src/storage/buffer/block_handle.cpp Outdated
D_ASSERT(!GetBuffer() || GetBuffer()->GetBufferType() == GetBufferType());
if (GetBuffer() && GetBufferType() != FileBufferType::TINY_BUFFER) {
// Kill the latest version in the eviction queue.
if (EverInEvictionQueue() && GetBufferType() != FileBufferType::TINY_BUFFER) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very interesting

return shared_memory_p;
}

bool BufferEvictionNode::IsDeadNode(idx_t debug_sleep_micros) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this debugging logic in the code?

krleonid and others added 5 commits May 17, 2026 19:20
…rInEvictionQueue

The ~BlockMemory destructor used a sticky flag (ever_in_eviction_queue) to
decide whether to call IncrementDeadNodes. After eviction via
IterateUnloadableBlocks, the queue entry is consumed (dequeued) and
eviction_seq_num is reset to 0 — but the flag remained true, causing
IncrementDeadNodes for a non-existent entry. In out-of-core workloads this
inflated total_dead_nodes unboundedly, making purge hold purge_lock for
excessive iterations and blocking eviction threads under memory pressure.

Fix: check GetEvictionSequenceNumber() > 0 — true iff there is a live queue
entry (reset to 0 on Unload). Remove the now-unused ever_in_eviction_queue
field and MarkAddedToEvictionQueue().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The move-assignment operator was missing the UpdateUsedMemory call to
release the old reservation's bytes, causing the pool to over-count
used memory and trigger premature OOM on spill-to-disk workloads.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Persistent segments are resized to block_size during checkpoint, so
passing them as the size hint for a new transient segment is misleading.
Pass nullptr instead to start fresh when appending after a persistent segment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… updates

Previously, each UpdateInfo for the root node allocated space for STANDARD_VECTOR_SIZE
entries regardless of how many rows were actually updated. For workloads with many sparse
updates across different vectors (e.g., 70K attached databases with scattered writes),
this caused massive memory waste — up to 98KB per updated vector with 16K vector size.

This change introduces compact allocation: the root UpdateInfo starts with capacity
rounded up to the next power of two (minimum 8), and re-allocates with doubled capacity
when more rows in the same vector are subsequently updated. For single-row-per-vector
updates, this reduces memory from ~98KB to ~168 bytes per allocation (586x reduction).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants