thetumbled commented on code in PR #18390:
URL: https://github.com/apache/pulsar/pull/18390#discussion_r1019328476
##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongLongPairHashMap.java:
##########
@@ -327,10 +330,24 @@ LongPair get(long key1, long key2, int keyHash) {
try {
while (true) {
// First try optimistic locking
- long storedKey1 = table[bucket];
- long storedKey2 = table[bucket + 1];
- long storedValue1 = table[bucket + 2];
- long storedValue2 = table[bucket + 3];
+ long storedKey1 = 0;
+ long storedKey2 = 0;
+ long storedValue1 = 0;
+ long storedValue2 = 0;
+ try {
+ storedKey1 = table[bucket];
+ storedKey2 = table[bucket + 1];
+ storedValue1 = table[bucket + 2];
+ storedValue2 = table[bucket + 3];
+ } catch (ArrayIndexOutOfBoundsException e) {
Review Comment:
we can detect whether ArrayIndexOutOfBoundsException is caused by a
concurrent execution, if not, we just throw out it.
```
try {
storedKey1 = table[bucket];
storedKey2 = table[bucket + 1];
storedValue1 = table[bucket + 2];
storedValue2 = table[bucket + 3];
} catch (ArrayIndexOutOfBoundsException e) {
// read a dirty capacity, cause
ArrayIndexOutOfBoundsException
if (validate(stamp)) {
throw e;
}
if (logger.isDebugEnabled()) {
logger.debug(
"Read a dirty capacity, fallback to
Pessimistic Read. capacity:{}, bucket:{}, "
+ "cause:{}",
capacity, bucket, e.getMessage());
}
}
```
--
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]