Skip to content

21671 direct io + readahead exception fix - #5152

Open
rustyrazorblade wants to merge 2 commits into
apache:trunkfrom
rustyrazorblade:21671-readahead-fix
Open

21671 direct io + readahead exception fix#5152
rustyrazorblade wants to merge 2 commits into
apache:trunkfrom
rustyrazorblade:21671-readahead-fix

Conversation

@rustyrazorblade

Copy link
Copy Markdown
Contributor

Fixes direct io + read ahead exception, CASSANRA-21671

@rustyrazorblade rustyrazorblade changed the title 21671 readahead fix 21671 direct io + readahead exception fix Sep 10, 2026
…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.
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.

1 participant