This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch branch-0.3
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git


The following commit(s) were added to refs/heads/branch-0.3 by this push:
     new 3a40d909a [CELEBORN-478] Replace putIfAbsent with computeIfAbsent in 
ConcurrentHashMap in Java code
3a40d909a is described below

commit 3a40d909a98bd44595e35194632bfab6d24bc9c4
Author: cchung100m <[email protected]>
AuthorDate: Thu Jun 29 16:44:18 2023 +0800

    [CELEBORN-478] Replace putIfAbsent with computeIfAbsent in 
ConcurrentHashMap in Java code
    
    ### What changes were proposed in this pull request?
    
    Replace `putIfAbsent` with computeIfAbsent in ConcurrentHashMap
    
    ### Why are the changes needed?
    
    The invoking of `putIfAbsent` will always call its value if it's a 
time-consuming operation. So we'd better replace `putIfAbsent` with 
`computeIfAbsent` in some critical paths.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No, it does not affect the user-facing API
    
    ### How was this patch tested?
    
    current UT
    
    Closes #1567 from cchung100m/CELEBORN-478.
    
    Lead-authored-by: cchung100m <[email protected]>
    Co-authored-by: Cheng Pan <[email protected]>
    Co-authored-by: Neo Chien <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
    (cherry picked from commit 4e1e97b2c2c329907ca45186f678c5afa64995e7)
    Signed-off-by: Cheng Pan <[email protected]>
---
 .../apache/celeborn/common/network/client/TransportClientFactory.java  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/common/src/main/java/org/apache/celeborn/common/network/client/TransportClientFactory.java
 
b/common/src/main/java/org/apache/celeborn/common/network/client/TransportClientFactory.java
index d8ba62911..bd01560c0 100644
--- 
a/common/src/main/java/org/apache/celeborn/common/network/client/TransportClientFactory.java
+++ 
b/common/src/main/java/org/apache/celeborn/common/network/client/TransportClientFactory.java
@@ -127,7 +127,8 @@ public class TransportClientFactory implements Closeable {
     // Create the ClientPool if we don't have it yet.
     ClientPool clientPool = connectionPool.get(unresolvedAddress);
     if (clientPool == null) {
-      connectionPool.putIfAbsent(unresolvedAddress, new 
ClientPool(numConnectionsPerPeer));
+      connectionPool.computeIfAbsent(
+          unresolvedAddress, key -> new ClientPool(numConnectionsPerPeer));
       clientPool = connectionPool.get(unresolvedAddress);
     }
 

Reply via email to