mike-tr-adamson commented on code in PR #2943:
URL: https://github.com/apache/cassandra/pull/2943#discussion_r1410910315
##########
src/java/org/apache/cassandra/index/sai/disk/v1/keystore/KeyLookup.java:
##########
@@ -265,42 +258,39 @@ public void reset() throws IOException
readCurrentKey();
}
-
@Override
public void close()
{
keysInput.close();
}
- private void updateCurrentBlockIndex(long pointId)
+ private int keyInBlockComparison(long pointId, BytesRef key)
{
- currentBlockIndex = pointId >>> blockShift;
- }
+ updateCurrentBlockIndex(pointId);
+ resetToCurrentBlock();
+ if (compareKeys(key, currentKey) < 0)
+ return -1;
- private boolean notInCurrentBlock(long pointId, BytesRef key)
- {
- if (inLastBlock(pointId))
- return false;
+ if (currentBlockIndex == blockOffsets.length() -1)
+ return 0;
- // Load the starting value of the next block into nextBlockKey.
- long blockIndex = (pointId >>> blockShift) + 1;
long currentFp = keysInput.getFilePointer();
- keysInput.seek(blockOffsets.get(blockIndex) + keysFilePointer);
- readKey(blockIndex << blockShift, nextBlockKey);
+ keysInput.seek(blockOffsets.get(currentBlockIndex + 1) +
keysFilePointer);
+ readKey((currentBlockIndex + 1) << blockShift, nextBlockKey);
keysInput.seek(currentFp);
-
- return compareKeys(key, nextBlockKey) >= 0;
+ return compareKeys(key, nextBlockKey) < 0 ? 0 : 1;
Review Comment:
Correct, I have added some comments to this method to make it clear what is
going on. I've also made some small optimisations to avoid unnecessary seeks.
--
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]