mike-tr-adamson commented on code in PR #2943:
URL: https://github.com/apache/cassandra/pull/2943#discussion_r1410899049
##########
src/java/org/apache/cassandra/index/sai/disk/v1/keystore/KeyLookup.java:
##########
@@ -197,43 +197,34 @@ public long clusteredSeekToKey(ByteComparable key, long
startingPointId, long en
updateCurrentBlockIndex(startingPointId);
resetToCurrentBlock();
- if (compareKeys(currentKey, skipKey) == 0)
- return startingPointId;
+ // We can return straightaway if the currentPointId is within the
requested partition range and the keys match
+ if (currentPointId >= startingPointId && currentPointId <
endingPointId && compareKeys(currentKey, skipKey) == 0)
+ return currentPointId;
- if (notInCurrentBlock(startingPointId, skipKey))
- {
- long split = (endingPointId - startingPointId) >>> blockShift;
- long splitPointId = startingPointId;
- while (split > 0)
- {
- updateCurrentBlockIndex(Math.min((splitPointId >>>
blockShift) + split, blockOffsets.length() - 1));
- resetToCurrentBlock();
+ long splitStartId = startingPointId;
+ long splitEndId = endingPointId;
- if (currentPointId >= endingPointId)
- {
- updateCurrentBlockIndex((endingPointId - 1));
- resetToCurrentBlock();
- }
-
- int cmp = compareKeys(currentKey, skipKey);
-
- if (cmp == 0)
- return currentPointId;
+ while ((splitEndId - splitStartId) >>> blockShift > 0)
+ {
+ long midPointId = splitStartId + (splitEndId - splitStartId) /
2;
- if (cmp < 0)
- splitPointId = currentPointId;
+ int position = keyInBlockComparison(midPointId, skipKey);
Review Comment:
I like `moveToBlockAndCompareTo`, so have changed it to that because it is
closer to the behaviour. I wanted the update and reset block in this method
because it shouldn't really be used without it. The name makes the binary
search clearer as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]