[ 
https://issues.apache.org/jira/browse/HDDS-15006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18072527#comment-18072527
 ] 

Attila Doroszlai commented on HDDS-15006:
-----------------------------------------

[~szetszwo], javadoc of {{ConcurrentHashMap#compute}} says:

bq. The entire method invocation is performed atomically. Some attempted update 
operations on this map by other threads may be blocked while computation is in 
progress 
([source|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html#compute-K-java.util.function.BiFunction-])

in Java 17's docs this was amended with:

bq. The supplied function is invoked exactly once per invocation of this 
method. 
([source|https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/concurrent/ConcurrentHashMap.html#compute(K,java.util.function.BiFunction)])

I don't think semantics of the method have changed, this extra sentence seems 
to be just a clarification.

In contrast, {{AtomicReference#updateAndGet}} documents that

bq. function should be side-effect-free, since it may be re-applied when 
attempted updates fail due to contention among threads. 
([source|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReference.html#updateAndGet-java.util.function.UnaryOperator-])

So I think it is safe to use {{ConcurrentHashMap#compute}} like 
{{XceiverClientGrpc}} does.

> XceiverClientGrpc may create and drop connections without closing it
> --------------------------------------------------------------------
>
>                 Key: HDDS-15006
>                 URL: https://issues.apache.org/jira/browse/HDDS-15006
>             Project: Apache Ozone
>          Issue Type: Bug
>          Components: Ozone Client
>            Reporter: Tsz-wo Sze
>            Assignee: Rishabh Patel
>            Priority: Major
>
> In HDDS-14571, it uses ConcurrentHashMap.compute(..) to create connection in 
> XceiverClientGrpc.  However, ConcurrentHashMap.compute(..) can use the 
> remappingFunction to create and drop objects when there is a race condition.  
> As a result, it may create a connection and then drop it without closing it.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to