Skip to content

Conversation

@eolivelli
Copy link

What is the issue

ConcurrentHashMap backing ChunkCache sometimes falls into Treeification ( O(log n) access time instead of O(1))

Full context in https://github.com/riptano/cndb/issues/16243

What does this PR fix and why was it fixed

  • Improve hashCode of the Key to prevent collisions
  • Implement Comparable in case the ConcurrentHashMap falls back in to Tree mode

@github-actions
Copy link

github-actions bot commented Dec 7, 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

Copy link

@pkolaczk pkolaczk left a comment

Choose a reason for hiding this comment

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

The change looks good. But this is something that can be easily (and cheaply) tested.
Especially it would be nice to reproduce the original issue in the test (like - which keys caused so many hashCollisions), and then demonstrate the the new hash is indeed better.

@eolivelli
Copy link
Author

But this is something that can be easily (and cheaply) tested.
I don't know if this is worth to do in a unit test.

I am using this patch in the 1B vectors POC and the ConcurrentHashMap now works much better.

I added unit tests (mostly generated by AI, with some modifications) to validate the implementation.
There is also a small test to try to test the distribution of hashCode

Copy link

@pkolaczk pkolaczk left a comment

Choose a reason for hiding this comment

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

Looks good now

@sonarqubecloud
Copy link

Improve hashCode of the Key to prevent collisions
Implement Comparable<Key> in case the ConcurrentHashMap falls back in to Tree mode
@cassci-bot
Copy link

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


1 regressions found
See build details here


Found 1 new test failures

Test Explanation Runs Upstream
o.a.c.index.sai.cql.VectorCompaction100dTest.testOneToManyCompactionTooManyHoles[db true] NEW 🔴 0 / 19

Found 1 known test failures

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