lhotari commented on code in PR #18390:
URL: https://github.com/apache/pulsar/pull/18390#discussion_r1312666391


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongLongPairHashMap.java:
##########
@@ -322,7 +325,10 @@ private static final class Section extends StampedLock {
         LongPair get(long key1, long key2, int keyHash) {
             long stamp = tryOptimisticRead();
             boolean acquiredLock = false;
-            int bucket = signSafeMod(keyHash, capacity);
+            // add local variable here, so OutOfBound won't happen
+            long[] table = this.table;
+            // calculate table.length / 4 as capacity to avoid rehash changing 
capacity
+            int bucket = signSafeMod(keyHash, table.length / ITEM_SIZE);

Review Comment:
   Btw, it seems that the original code has a bug in calculating the index in 
`table` for the bucket. I think that it's a a bug in the original code. It 
seems that there should be a separate `bucketIndex` variable which is 
calculated by `bucket * ITEM_SIZE`. @merlimat WDYT?



-- 
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]

Reply via email to