[ 
https://issues.apache.org/jira/browse/HDDS-15006?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tsz-wo Sze updated HDDS-15006:
------------------------------
    Description: 
{code:java}
//XceiverClientGrpc
  private final ConcurrentMap<DatanodeID, ChannelInfo> dnChannelInfoMap;
{code}

In HDDS-14571, it uses 
[ConcurrentMap.compute|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentMap.html#compute-K-java.util.function.BiFunction-]
 to create connection in XceiverClientGrpc. However, the remappingFunction may 
be called multiple times to create and drop objects as mentioned in the javadoc 
. As a result, it may create a connection and then drop it without closing it.

- Note that the current code indeed does not have a bug

since it uses ConcurrentHashMap which calls the remappingFunction exactly once. 
However, it may become a bug when changing to other ConcurrentMap 
implementation.

Also, it is more efficient to make the remapping function light weighted so it 
won't hold the lock for a long time. It is generally a good practices as method 
in 
[ConcurrentHashMap.compute|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html#compute-K-java.util.function.BiFunction-].

  was: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.

     Issue Type: Improvement  (was: Bug)
        Summary: XceiverClientGrpc.connectToDatanode should not create 
connections in the remapping function  (was: XceiverClientGrpc may create and 
drop connections without closing it)

> XceiverClientGrpc.connectToDatanode should not create connections in the 
> remapping function
> -------------------------------------------------------------------------------------------
>
>                 Key: HDDS-15006
>                 URL: https://issues.apache.org/jira/browse/HDDS-15006
>             Project: Apache Ozone
>          Issue Type: Improvement
>          Components: Ozone Client
>            Reporter: Tsz-wo Sze
>            Assignee: Rishabh Patel
>            Priority: Major
>
> {code:java}
> //XceiverClientGrpc
>   private final ConcurrentMap<DatanodeID, ChannelInfo> dnChannelInfoMap;
> {code}
> In HDDS-14571, it uses 
> [ConcurrentMap.compute|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentMap.html#compute-K-java.util.function.BiFunction-]
>  to create connection in XceiverClientGrpc. However, the remappingFunction 
> may be called multiple times to create and drop objects as mentioned in the 
> javadoc . As a result, it may create a connection and then drop it without 
> closing it.
> - Note that the current code indeed does not have a bug
> since it uses ConcurrentHashMap which calls the remappingFunction exactly 
> once. However, it may become a bug when changing to other ConcurrentMap 
> implementation.
> Also, it is more efficient to make the remapping function light weighted so 
> it won't hold the lock for a long time. It is generally a good practices as 
> method in 
> [ConcurrentHashMap.compute|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html#compute-K-java.util.function.BiFunction-].



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