You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celeborn.apache.org by ch...@apache.org on 2023/06/29 08:44:27 UTC

[incubator-celeborn] branch main updated: [CELEBORN-478] Replace putIfAbsent with computeIfAbsent in ConcurrentHashMap in Java code

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

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


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

commit 4e1e97b2c2c329907ca45186f678c5afa64995e7
Author: cchung100m <cc...@cs.ccu.edu.tw>
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 <cc...@cs.ccu.edu.tw>
    Co-authored-by: Cheng Pan <ch...@apache.org>
    Co-authored-by: Neo Chien <cc...@cs.ccu.edu.tw>
    Signed-off-by: Cheng Pan <ch...@apache.org>
---
 .../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);
     }