-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Closed
Labels
type/bugThe PR fixed a bug or issue reported a bugThe PR fixed a bug or issue reported a bug
Description
Search before asking
- I searched in the issues and found nothing similar.
Version
master
Minimal reproduce step
ConcurrentSkipListMap#computeIfAbsent does not guarantee only calling the supplier atomically when the value is not present. The following usage appears to be side effecting code that will likely break due to misuse of this method:
pulsar/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/util/RangeCache.java
Lines 78 to 82 in 82237d3
| entries.computeIfAbsent(key, (k) -> { | |
| size.addAndGet(weighter.getSize(value)); | |
| flag.setValue(true); | |
| return value; | |
| }); |
What did you expect to see?
We need to make sure that we only increment those atomic counters once.
What did you see instead?
There is a chance we'll increment the counters in certain race conditions.
Anything else?
Relevant context can be found here: datastax/cassandra#789 (comment)
Are you willing to submit a PR?
- I'm willing to submit a PR!
Metadata
Metadata
Assignees
Labels
type/bugThe PR fixed a bug or issue reported a bugThe PR fixed a bug or issue reported a bug