forked from apache/cassandra
-
Notifications
You must be signed in to change notification settings - Fork 21
CNDB-15485: Fix ResultRetriever key comparison to prevent dupes in result set (#2024) #2092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Checklist before you submit for review
|
9e8ccb3 to
7e937d7
Compare
eolivelli
approved these changes
Oct 29, 2025
eolivelli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/java/org/apache/cassandra/index/sai/plan/StorageAttachedIndexSearcher.java
Show resolved
Hide resolved
…sult set (#2024) (cherry picked from commit ada025c) Copy of #2023, but targeting `cndb-main-release-202510` branch. riptano/cndb#15485 This PR fixes a bug introduced to this branch via #1884. The bug only impacts SAI file format `aa` when the index file was produced via compaction, which is why the modified test simply adds coverage to compact the table and hit the bug. The bug happens when an iterator produces the same partition across two different batch fetches from storage. These keys were not collapsed in the `key.equals(lastKey)` logic because compacted indexes use a row id per row instead of per partition, and the logic in `PrimaryKeyWithSource` considers rows with different row ids to be distinct. However, when we went to materialize a batch from storage, we hit this code: ```java ClusteringIndexFilter clusteringIndexFilter = command.clusteringIndexFilter(firstKey.partitionKey()); if (cfs.metadata().comparator.size() == 0 || firstKey.hasEmptyClustering()) { return clusteringIndexFilter; } else { nextClusterings.clear(); for (PrimaryKey key : keys) nextClusterings.add(key.clustering()); return new ClusteringIndexNamesFilter(nextClusterings, clusteringIndexFilter.isReversed()); } ``` which returned `clusteringIndexFilter` for `aa` because those indexes do not have the clustering information. Therefore, each batch fetched the whole partition (which was subsequently filtered to the proper results), and produced a multiplier effect where we saw `batch` many duplicates. This fix works by comparing partition keys and clustering keys directly, which is a return to the old comparison logic from before #1884. There was actually a discussion about this in the PR to `main`, but unfortunately, we missed this case #1883 (comment). A more proper long term fix might be to remove the logic of creating a `PrimaryKeyWithSource` for AA indexes. However, I preferred this approach because it is essentially a `revert` instead of fixing forward solution.
7e937d7 to
40f06b7
Compare
|
❌ Build ds-cassandra-pr-gate/PR-2092 rejected by Butler1 regressions found Found 1 new test failures
No known test failures found |
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.



CNDB-15485: Fix ResultRetriever key comparison to prevent dupes in result set (#2024)
(cherry picked from commit ada025c)
Copy of #2023, but targeting
cndb-main-release-202510branch.https://github.com/riptano/cndb/issues/15485
This PR fixes a bug introduced to this branch via
#1884. The bug only impacts
SAI file format
aawhen the index file was produced via compaction,which is why the modified test simply adds coverage to compact the table
and hit the bug.
The bug happens when an iterator produces the same partition across two
different batch fetches from storage. These keys were not collapsed in
the
key.equals(lastKey)logic because compacted indexes use a row idper row instead of per partition, and the logic in
PrimaryKeyWithSourceconsiders rows with different row ids to bedistinct. However, when we went to materialize a batch from storage, we
hit this code:
which returned
clusteringIndexFilterforaabecause those indexes donot have the clustering information. Therefore, each batch fetched the
whole partition (which was subsequently filtered to the proper results),
and produced a multiplier effect where we saw
batchmany duplicates.This fix works by comparing partition keys and clustering keys directly,
which is a return to the old comparison logic from before
#1884. There was actually a
discussion about this in the PR to
main, but unfortunately, we missedthis case
#1883 (comment).
A more proper long term fix might be to remove the logic of creating a
PrimaryKeyWithSourcefor AA indexes. However, I preferred thisapproach because it is essentially a
revertinstead of fixing forwardsolution.