Skip to content

Conversation

jasonstack
Copy link

@jasonstack jasonstack commented Sep 17, 2025

What is the issue

CNDB-15393 - ShardManager#coveringRange returns a range missing left position and the ShardManager#rangeSpanned for (min, min] is not 1.

What does this PR fix and why was it fixed

Create Range with (left-1, right] to make sure both left and right are included. And make sure range span is 1 for (min, min]

Copy link

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

@jasonstack jasonstack requested a review from blambov September 17, 2025 10:02
@jasonstack jasonstack changed the title CNDB-15331: fix ShardManager#coveringRange to decrement left instead of incrementing right CNDB-15393: fix ShardManager#coveringRange to decrement left instead of incrementing right Sep 17, 2025
@Override
public Token prevValidToken()
{
return isMinimum() ? new LongToken(Long.MAX_VALUE) : new LongToken(token - 1);
Copy link

Choose a reason for hiding this comment

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

Nit: I would let wraparound take care of the min->max transition as in nextValidToken.

Note: Any decorated key would have a non-minimum token, so wraparound here could not happen for sstable start keys.

Copy link
Author

Choose a reason for hiding this comment

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

fixed in 26932c4

@Override
public Token prevValidToken()
{
BigInteger prev = this.isMinimum() || token.compareTo(ZERO) == 0
Copy link

Choose a reason for hiding this comment

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

Hmm. MINIMUM is not a real ring position, but it makes better sense for what we are trying to do with this method as an adjustment for a ZERO token for an SSTable's first key. There is some risk that wrapping around will cause trouble in some function that is only written to work with non-wraparound ranges: these normally accept minimum as the upper bound, but not maximum on the lower side.

I would change this to go from ZERO to MINIMUM and either not touch MINIMUM or wrap it around. I know this means MAXIMUM.nextValidToken().prevValidToken() != MAXIMUM, but that's something I'd more easily accept (especially if we add a comment).

Copy link
Author

Choose a reason for hiding this comment

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

good point. fixed in 26932c4

…of incrementing right, because Range is left exclusive

* Added Token#prevValidToken to return previous possible tokens for 2 hashing partitioner
@jasonstack
Copy link
Author

UnifiedCompactionStrategyTest.testGetBucketsDifferentWsUniqueArena unit test failed because it uses min token as DecoractedKey for SSTable#first key (DecoratedKey first = new BufferDecoratedKey(partitioner.getMinimumToken(), ByteBuffer.allocate(0))) and DecoratedKey#isMinimal is always false. Thus ShardManager#coveringRange retrun (max, max] which is a wrap around range.

I have pushed e71ac0f to check if token is minimal instead of checking if partition-position is minimal. @blambov wdyt?

Copy link

@jasonstack jasonstack merged commit 0be2515 into main Sep 23, 2025
489 of 494 checks passed
@jasonstack jasonstack deleted the cndb-15331-main branch September 23, 2025 07:24
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.

3 participants