Skip to content

CNDB-15608 port CASSANDRA-18673 to reduce disk usage of row-aware indexes in 5.0 - #2568

Open
k-rus wants to merge 3 commits into
main-5.0from
rf-5.0-15608-reduce-disk-size
Open

CNDB-15608 port CASSANDRA-18673 to reduce disk usage of row-aware indexes in 5.0#2568
k-rus wants to merge 3 commits into
main-5.0from
rf-5.0-15608-reduce-disk-size

Conversation

@k-rus

@k-rus k-rus commented Aug 15, 2026

Copy link
Copy Markdown
Member

Cherry-pick of #2122 to main-5.0. Fixes https://github.com/riptano/cndb/issues/15608, https://github.com/riptano/cndb/issues/17164, https://github.com/riptano/cndb/issues/17948
CNDB PR: https://github.com/riptano/cndb/pull/16672

Row aware SAI format increases significantly the size of SAI on disk. This increases the disk cost and creates incidents due to not enough disk space when SAI format version is changed from AA to newer version.

This ports patches CASSANDRA-18673 to reduce disk size, and CASSANDRA-19011 to fix bug and improve the code in the initial patch.

The disk size is reduced as compression is improved due to not prefixing with tokens, and due to removed a trie structure for storing sorted terms.

The patch implements new disk format for SAI (GA, v9), which changes how row aware primary key map is stored in components. The primary key map is split into storing partition key map and clustering key map in separate components. Both, partition key map and clustering key map, use Key Store coming from Apache, which replaces the sorted terms structure of row aware primary key maps. As result the structure doesn't require ordering primary keys on partition keys and it's up to the caller to preserve the order and is preserved during flush by ordering on tokens. Partition keys are stored without token prefix to allow better compression. Clustering keys are sorted lexicographically within a partition.

KeyLookup does not use tries terms dictionary, which used in SortedTerms. This requires to implement ceiling and floor methods in LondArray implementations. My understanding is that ceiling and floor methods are used for sorting and ANN. This doesn't exist in Apache.

Because of specific case for clustering it was necessary to propagate and store a clustering flag and clustering comparator into index components and index descriptor.

Tests are added to cover ported structures for new primary key map and its components.

Other things got in with the ports of the patches:

  • Replace hasEmptyClustering methods with hasClustering, so it's consistently used only hasClustering.
  • Add error message on error during primary key map creation due to cursor failure.

An attempt to reduce code duplications is included. It's mainly for primary key map and its tests, which required some refactoring.

…exes (#2122)

Row aware SAI format increases significantly the size of SAI on disk.
This increases the disk cost and creates incidents due to not enough
disk space when SAI format version is changed from AA to newer version.

This ports patches CASSANDRA-18673 to reduce disk size, and
CASSANDRA-19011 to fix bug and improve the code in the initial patch.

The disk size is reduced as compression is improved due to not prefixing
with tokens, and due to removed a trie structure for storing sorted
terms.

The patch implements new disk format for SAI (GA, v9), which changes
how row aware primary key map is stored in components. The primary key
map is split into storing partition key map and clustering key map in
separate components. Both, partition key map and clustering key map, use
Key Store coming from Apache, which replaces the sorted terms structure
of row aware primary key maps. As result the structure doesn't require
ordering primary keys on partition keys and it's up to the caller to
preserve the order and is preserved during flush by ordering on tokens.
Partition keys are stored without token prefix to allow better
compression. Clustering keys are sorted lexicographically within a
partition.

KeyLookup does not use tries terms dictionary, which used in
SortedTerms. This requires to implement ceiling and floor methods in
LondArray implementations. My understanding is that ceiling and floor
methods are used for sorting and ANN. This doesn't exist in Apache.

Because of specific case for clustering it was necessary to propagate
and store a clustering flag and clustering comparator into index
components and index descriptor.

Tests are added to cover ported structures for new primary key map and
its components.

Other things got in with the ports of the patches:
- Replace `hasEmptyClustering` methods with `hasClustering`, so it's
consistently used only `hasClustering`.
- Add error message on error during primary key map creation due to
cursor failure.

An attempt to reduce code duplications is included. It's mainly for
primary key map and its tests, which required some refactoring.

---------

Co-authored-by: Mike Adamson <madamson@datastax.com>
@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown

Checklist before you submit for review

  • This PR adheres to the Definition of Done
  • Make sure there is a PR and ticket 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%, check manually at SonarCloud page
  • 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 IBM copyright header instead of the Apache License one (no DataStax copyright any longer)

@k-rus

k-rus commented Aug 17, 2026

Copy link
Copy Markdown
Member Author

11 regressions found See build details here

Known failures and unrelated to the PR.

@k-rus
k-rus requested review from adelapena and pkolaczk August 17, 2026 10:16
@k-rus

k-rus commented Aug 17, 2026

Copy link
Copy Markdown
Member Author

`KeyLookupTest` tests `KeyLookup` introduced in v9 SAI disk format,
which is used from `GA` version. However, the component file validation
uses the default version, which is the earliest, i.e., `AA`.

Specifies SAI format `GA`in validating components in `KeyLookupTest`
instead of relying on default, which is the earliest SAI format, i.e.,
`AA`.
@sonarqube-dx-prod

Copy link
Copy Markdown

@plpesvc-ds

Copy link
Copy Markdown

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


4 regressions found
See build details here


Found 4 new test failures

Test Explanation Runs Upstream
junit.framework.TestSuite.org.apache.cassandra.distributed.test.sai.features.FeaturesVersionSupportAATest-_jdk11 REGRESSION 🔴🔵 0 / 30
junit.framework.TestSuite.org.apache.cassandra.distributed.test.sai.features.FeaturesVersionSupportBATest-_jdk11 REGRESSION 🔴🔵 0 / 30
o.a.c.index.sai.cql.VectorCompaction100dTest.testPQRefine[version=ec enableNVQ=false] () NEW 🔴 0 / 30
o.a.c.index.sai.cql.VectorSiftSmallTest.testMultiSegmentBuild[ed false] () NEW 🔴 0 / 30

Found 4 known test failures

@k-rus

k-rus commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

Nightly build doesn't find new test failures. Reported failures are unrelated to the PR.

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.

2 participants