21671 direct io + readahead exception fix - #5152
Open
rustyrazorblade wants to merge 2 commits into
Open
Conversation
…buffer The compressed read-ahead buffer was owned by the single scanReader field of a shared CompressedChunkReader, so one buffer was reused across every reader of the file and across threads. To make that shared object safe, its state lived in a static per-thread, per-path Block map. That cross-instance, cross-thread reuse caused the reinit and double-free faults on this path. Own the read-ahead buffer on the per-scan reader instead. forScan() now returns a per-reader view that owns a plain buffer, allocated on open and freed on close. Each scan reader is single-threaded, so no buffer is shared across threads and no thread-local state is needed. N scanners over N inputs give N buffers by construction. Remove the static Block map, the bufferSize == -1 reinit, and the aligned slice resolution in cleanBuffer; each buffer class now frees the buffer type it allocates. Rename ThreadLocalReadAheadBuffer to ReadAheadBuffer and DirectThreadLocalReadAheadBuffer to DirectReadAheadBuffer, since the names no longer describe thread-local state. Add a concurrent-scan test that reads one file from several threads at once, plus per-instance ownership and lifecycle tests.
CachingRebufferer.instantiateRebufferer(isScan) returned this, so it dropped the isScan flag. A scan with the chunk cache on therefore populated the cache with one-shot chunks and evicted hot data. Delegate to the source when isScan is true, so the scan bypasses the cache and uses its own read-ahead buffer. For an Mmap source this also bypasses the chunk cache, which is correct: mmap data already lives in the OS page cache, so the chunk cache only duplicates it. Add ChunkCacheScanBypassTest: a scan adds nothing to the cache while a point read populates it, and a scan under the cache still reads through the read-ahead buffer.
rustyrazorblade
force-pushed
the
21671-readahead-fix
branch
from
September 14, 2026 01:15
4e74910 to
3143ff5
Compare
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.
Fixes direct io + read ahead exception, CASSANRA-21671