[
https://issues.apache.org/jira/browse/HDDS-15006?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tsz-wo Sze updated HDDS-15006:
------------------------------
Description:
(Revised)
{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 (thanks [~adoroszlai]
for pointing it out)
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
mentioned in
[ConcurrentHashMap.compute|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html#compute-K-java.util.function.BiFunction-].
was:
(Revised)
{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
mentioned in
[ConcurrentHashMap.compute|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html#compute-K-java.util.function.BiFunction-].
> 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
>
> (Revised)
> {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 (thanks
> [~adoroszlai] for pointing it out)
> 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
> mentioned 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]