Skip to content

CASSANDRA-21085 Preserve offsets when splitting cache eviction requests larger than 2 GiB - #5134

Open
cheeeee wants to merge 1 commit into
apache:trunkfrom
cheeeee:CASSANDRA-21085-trunk
Open

CASSANDRA-21085 Preserve offsets when splitting cache eviction requests larger than 2 GiB#5134
cheeeee wants to merge 1 commit into
apache:trunkfrom
cheeeee:CASSANDRA-21085-trunk

Conversation

@cheeeee

@cheeeee cheeeee commented Sep 9, 2026

Copy link
Copy Markdown

CASSANDRA-21085 reports "Failed trySkipCache on file: ... Error: Invalid argument" during compaction.

NativeLibrary.trySkipCache(fd, offset, len, path) splits a request into int-sized chunks for the native
binding. After the first chunk it subtracted the chunk length from the offset instead of adding it, so
every following chunk was issued with a negative offset and posix_fadvise returned EINVAL. This can only
happen when the requested range exceeds Integer.MAX_VALUE bytes, i.e. on data files larger than 2 GiB.
Separately, a zero-length request (meaning "to end of file") dropped its starting offset and was issued
from 0.

Changes:

  • advance the offset after each chunk;
  • keep the requested starting offset when len == 0;
  • size chunks at 2 GiB rounded down to a 2 MiB multiple (FADVISE_MAX_CHUNK) instead of Integer.MAX_VALUE.
    POSIX_FADV_DONTNEED only drops pages fully covered by the range, so an unaligned chunk boundary leaves
    the page that straddles it resident; a boundary that is a multiple of every common page size
    (4K, 16K, 64K) does not.

Testing:

  • NativeLibraryTest: testSkipCacheLargeRange (Byteman on the native call; asserts the exact (offset, len)
    tuples for a range of 2 * FADVISE_MAX_CHUNK + 17 bytes, three calls), testSkipCacheZeroLength (offset
    preserved), testSkipCache.
  • Kernel-level check, Linux 6.19, ext4, 4 KiB pages, sparse 2 GiB + 8 MiB file: DONTNEED issued in
    Integer.MAX_VALUE chunks leaves the page straddling the first chunk boundary resident (mincore: 1 page);
    issued in FADVISE_MAX_CHUNK chunks it is evicted (0 pages).

CASSANDRA-21085

@cheeeee
cheeeee force-pushed the CASSANDRA-21085-trunk branch from 39b4689 to e657cd2 Compare September 11, 2026 22:50
@cheeeee cheeeee changed the title CASSANDRA-21085: Fix offset calculation in NativeLibrary.trySkipCache for files > 2GB CASSANDRA-21085 Preserve offsets when splitting cache eviction requests larger than 2 GiB Sep 11, 2026
Advance the offset after each bounded native request and preserve the
requested starting offset when length zero means the remainder of a file.
Cover multi-chunk ranges and the zero-length boundary at the native call
interface.

CASSANDRA-21085

Generated-by: Claude (Anthropic)
@cheeeee
cheeeee force-pushed the CASSANDRA-21085-trunk branch from e657cd2 to 46d7230 Compare September 12, 2026 02:49
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