Skip to content

Conversation

pcmanus
Copy link

@pcmanus pcmanus commented Sep 10, 2025

This PR is in the context of https://github.com/riptano/cndb/pull/15380, and is used by its PR https://github.com/riptano/cndb/pull/15380.

It adds a variant of the SSTableReader#getPositionsForRanges method that never read the data file to return its results, but in exchange may return positions that slightly "overshoot" the requested range.

Put another way, the added method SSTableReader#getApproximatePositionsForRanges is such that if you call it on some range R, and you read the data within the returned positions, then the read data may start by one (at most) key (partition really) that sorts strictly before R, and may end by one (at most) key that sorts strictly after R.

Additionally, the PR switches the reading of the Statistics.db component from using RandomAccessReader to using FileInputStreamPlus. This is essentially equivalent functionality wise (since the component is deserialized sequentially anyway, there is no random reads), but by making it more "clear" that it doesn't do random reads, it allows us to "direct download" this component like other related components on the CNDB side. See the last point of https://github.com/riptano/cndb/pull/15380 for more details.

Copy link

github-actions bot commented Sep 10, 2025

Checklist before you submit for review

  • This PR adheres to the Definition of Done
  • Make sure there is a PR in the CNDB project updating the Converged Cassandra version
  • Use NoSpamLogger for log lines that may appear frequently in the logs
  • Verify test results on Butler
  • Test coverage for new/modified code is > 80%
  • Proper code formatting
  • Proper title for each commit staring with the project-issue number, like CNDB-1234
  • Each commit has a meaningful description
  • Each commit is not very long and contains related changes
  • Renames, moves and reformatting are in distinct commits
  • All new files should contain the DataStax copyright header instead of the Apache License one

@pcmanus pcmanus force-pushed the CNDB-15300-approx-get-position branch 2 times, most recently from 7429e16 to 33e456d Compare September 16, 2025 14:48
@pcmanus pcmanus marked this pull request as ready for review September 17, 2025 12:02
@pcmanus
Copy link
Author

pcmanus commented Sep 17, 2025

@blambov: I'd appreciate a look, at least at the first commit, as it involves trie stuff. This isn't very complex, but would like to make sure I didn't made an incorrect assumption in there (and/or missed a better way to do this).

@pcmanus pcmanus force-pushed the CNDB-15300-approx-get-position branch from 33e456d to 272748a Compare September 17, 2025 16:05
Copy link

@jasonstack jasonstack left a comment

Choose a reason for hiding this comment

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

The changes look good, but I am not familiar with trie code. I will leave it to @blambov

Copy link

@blambov blambov left a comment

Choose a reason for hiding this comment

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

Thank you for the rework, this is much easier to follow.

@pcmanus pcmanus force-pushed the CNDB-15300-approx-get-position branch from 272748a to 647368c Compare September 19, 2025 08:53
@pcmanus
Copy link
Author

pcmanus commented Sep 22, 2025

Note: cove coverage is not happy, and this seem to be mostly because I copied the filterFirst()/filterLast() handling from getPosition and its not tested. I initially want to add quick tests, but it's actually annoying to test because zero-copy isn't even supported by the current sstable version. But that really highlights that we'll probably never need filterFirst()/filterLast() in this method, and so I've removed it to please coverage (with assertions to make sure it is indeed not called when those would matter). Let's see if coverage is ok now.

In the context of CNDB-15300, adds a variant of the
`SSTableReader#getPositionsForRanges` method that never read
the data file to return its results, but in exchange may return
positions that slightly "overshoot" the requested range.

Put another way, the added method `SSTableReader#getApproximatePositionsForRanges`
is such that if you call it on some range `R`, and you read the data
within the returned positions, then the read data may start by one (at
most) key (partition really) that sorts strictly before `R`, and may end
by one (at most) key that stort strictly after `R`.
The STATS component deserialization method, `MetadataSerializer#deserialize`
was creating a `RandomAccessReader` (RAR) to read the underlying file. But the
deserialization does not do "random" accesses, it strictly deserialize
sequentially.

In principle, using a RAR to do sequential reads is fine (though slighly
overkill), but it does mean that the method used on the underlying `FileChannel`
will be an "absolute" read (that take its position as argument, instead
of reading at the channel position), and tiered-storage extensions with
custom file channel may be able to use simple/more optimal
implementations when then know the file is read sequentially (only
through "relative" read calls).

Tl;dr, this replace the use of RAR by `FileInputStreamPlus`, which is
essentially equivalent in this use case, but does only do relative
reads.
Cove coverage complains it isn't tested, it is a bit involved to
actually test, and we actually don't need (at least not yet) this
method in those cases. In other words, this was kind of dead code,
so removing with assertions to prevent future misuse.
@pcmanus pcmanus force-pushed the CNDB-15300-approx-get-position branch from 6135469 to 1cee610 Compare September 23, 2025 08:37
Copy link

@cassci-bot
Copy link

❌ Build ds-cassandra-pr-gate/PR-1993 rejected by Butler


2 regressions found
See build details here


Found 2 new test failures

Test Explanation Runs Upstream
test_unicode.TestCqlshUnicode.test_unicode_desc (python3.8.jdk11.no-cython.x86_64) REGRESSION 🔴🔵 0 / 5
o.a.c.index.sai.cql.VectorUpdateDeleteTest.testTTLOverwriteHasCorrectOnDiskRowCount[ca] (compression) REGRESSION 🔴🔵 0 / 5

Found 2 known test failures

@pcmanus pcmanus merged commit 6383d21 into main Sep 24, 2025
483 of 494 checks passed
@pcmanus pcmanus deleted the CNDB-15300-approx-get-position branch September 24, 2025 13:46
michaelsembwever pushed a commit that referenced this pull request Sep 26, 2025
…Ranges` (#1993)

This PR is in the context of riptano/cndb#15380,
and is used by its PR riptano/cndb#15380.

It adds a variant of the `SSTableReader#getPositionsForRanges` method
that never read the data file to return its results, but in exchange may
return positions that slightly "overshoot" the requested range.

Put another way, the added method
`SSTableReader#getApproximatePositionsForRanges` is such that if you
call it on some range `R`, and you read the data within the returned
positions, then the read data may start by one (at most) key (partition
really) that sorts strictly before `R`, and may end by one (at most) key
that sorts strictly after `R`.

Additionally, the PR switches the reading of the `Statistics.db`
component from using `RandomAccessReader` to using
`FileInputStreamPlus`. This is essentially equivalent functionality wise
(since the component is deserialized sequentially anyway, there is no
random reads), but by making it more "clear" that it doesn't do random
reads, it allows us to "direct download" this component like other
related components on the CNDB side. See the last point of
riptano/cndb#15380 for more details.
michaelsembwever pushed a commit that referenced this pull request Oct 14, 2025
…Ranges` (#1993)

This PR is in the context of riptano/cndb#15380,
and is used by its PR riptano/cndb#15380.

It adds a variant of the `SSTableReader#getPositionsForRanges` method
that never read the data file to return its results, but in exchange may
return positions that slightly "overshoot" the requested range.

Put another way, the added method
`SSTableReader#getApproximatePositionsForRanges` is such that if you
call it on some range `R`, and you read the data within the returned
positions, then the read data may start by one (at most) key (partition
really) that sorts strictly before `R`, and may end by one (at most) key
that sorts strictly after `R`.

Additionally, the PR switches the reading of the `Statistics.db`
component from using `RandomAccessReader` to using
`FileInputStreamPlus`. This is essentially equivalent functionality wise
(since the component is deserialized sequentially anyway, there is no
random reads), but by making it more "clear" that it doesn't do random
reads, it allows us to "direct download" this component like other
related components on the CNDB side. See the last point of
riptano/cndb#15380 for more details.
michaelsembwever pushed a commit that referenced this pull request Oct 14, 2025
…Ranges` (#1993)

This PR is in the context of riptano/cndb#15380,
and is used by its PR riptano/cndb#15380.

It adds a variant of the `SSTableReader#getPositionsForRanges` method
that never read the data file to return its results, but in exchange may
return positions that slightly "overshoot" the requested range.

Put another way, the added method
`SSTableReader#getApproximatePositionsForRanges` is such that if you
call it on some range `R`, and you read the data within the returned
positions, then the read data may start by one (at most) key (partition
really) that sorts strictly before `R`, and may end by one (at most) key
that sorts strictly after `R`.

Additionally, the PR switches the reading of the `Statistics.db`
component from using `RandomAccessReader` to using
`FileInputStreamPlus`. This is essentially equivalent functionality wise
(since the component is deserialized sequentially anyway, there is no
random reads), but by making it more "clear" that it doesn't do random
reads, it allows us to "direct download" this component like other
related components on the CNDB side. See the last point of
riptano/cndb#15380 for more details.
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.

4 participants