Skip to content

CASSANDRA-21085: Fix offset calculation in NativeLibrary.trySkipCache for files > 2GB - #5134

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

CASSANDRA-21085: Fix offset calculation in NativeLibrary.trySkipCache for files > 2GB#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

Jira Issue

Motivation

In NativeLibrary.trySkipCache(int fd, long offset, long len, String path), the chunking loop across 2GB boundaries decremented offset (offset -= sublen) instead of incrementing it (offset += sublen). On SSTables larger than 2GB, the second and subsequent iterations passed negative offsets to posix_fadvise(..., POSIX_FADV_DONTNEED).

This caused:

  1. posix_fadvise returning -EINVAL (Invalid argument), flooding server logs with:
    WARN Failed trySkipCache on file: ... Error: Invalid argument
  2. Failure to evict page cache pages beyond the first 2GB of large SSTables during compaction and sstableupgrade.

Additionally, when len == 0, trySkipCache(fd, offset, 0, path) was hardcoding 0 as the offset, ignoring the requested starting offset.

Changes

  1. Fixed offset arithmetic in NativeLibrary.trySkipCache: offset += sublen;.
  2. When len == 0, pass offset to correctly drop from offset to EOF.
  3. Added unit test testSkipCacheLargeFile in NativeLibraryTest covering multi-chunk execution across the 2GB boundary.

Testing & Kernel eBPF Verification

  • NativeLibraryTest: 3/3 tests pass.
  • Linux Kernel eBPF Trace (tracepoint:syscalls:sys_enter_fadvise64):
    • Before fix:
      • Chunk 1: offset = 0, len = 2147483647
      • Chunk 2: offset = -2147483647, len = 1073741825 (negative offset, returns EINVAL).
    • After fix:
      • Chunk 1: offset = 0, len = 2147483647
      • Chunk 2: offset = 2147483647, len = 1073741825 (contiguous positive offset, returns 0).

…(CASSANDRA-21085)

In NativeLibrary.trySkipCache(int fd, long offset, long len, String path),
the chunking loop across 2GB boundaries decremented offset (offset -= sublen)
instead of incrementing it (offset += sublen). On SSTables larger than 2GB,
the second and subsequent iterations passed negative offsets to
posix_fadvise(..., POSIX_FADV_DONTNEED).

This caused:
1. posix_fadvise returning EINVAL (Invalid argument), flooding logs with
   'Failed trySkipCache on file: ... Error: Invalid argument'.
2. Failure to evict page cache pages beyond the first 2GB of large SSTables
   during compaction and sstableupgrade.

Additionally, when len == 0, pass the actual offset instead of hardcoding 0.

Fixes: CASSANDRA-21085
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