[fix] Fix ConcurrentLongHashMap concurrency issue#4317
[fix] Fix ConcurrentLongHashMap concurrency issue#4317dao-jun wants to merge 4 commits intoapache:masterfrom
Conversation
get|
It looks other Concurrent containers has the same issue, I'll create PRs to fix them one by one. |
|
I created an issue for tracking it #4318 |
|
BTW, the key point is int capacity = this.capacity;
bucket = signSafeMod(bucket, capacity);and // First try optimistic locking
long storedKey = keys[bucket];
V storedValue = values[bucket];not an atomic operation. If |
lhotari
left a comment
There was a problem hiding this comment.
Thanks for reporting the issue and starting the work to fix this issue.
Catching the exception would be the preferred solution since there's no point of using a StampedLock unless optimistic locking is used.
I think that we had this same bug discussed years ago, but for some reason we didn't fix this.
|
Found the discussion from the past: apache/pulsar#18390 (comment) . @thetumbled had originally made a PR to catch IndexOutOfBoundsException, which I think is the correct solution. |
|
I have created this pr to fix the issue in bookkeeper: #4066, can we move forward with it? @lhotari @hangc0276 @eolivelli @wenbingshen @zymap @shoothzj @horizonzy |
|
Let's close this PR and continue with #4066 |
|
Good! Let's continue with #4066 |
Descriptions of the changes in this PR:
Motivation
Fix ConcurrentLongHashMap can be ArrayIndexOutBound when call
getChanges
(Describe: what changes you have made)
Master Issue: #4316