hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cli...@apache.org
Subject hadoop git commit: HDFS-11850. Ozone: Stack Overflow in XceiverClientManager because of race condition in accessing openClient. Contributed by Mukul Kumar Singh.
Date Mon, 22 May 2017 17:20:14 GMT
Repository: hadoop
Updated Branches:
  refs/heads/HDFS-7240 b4e5c5543 -> b72ac9273


HDFS-11850. Ozone: Stack Overflow in XceiverClientManager because of race condition in accessing
openClient. Contributed by Mukul Kumar Singh.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b72ac927
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b72ac927
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b72ac927

Branch: refs/heads/HDFS-7240
Commit: b72ac9273e9a613d300c4d4ffaf0f466aeab10e1
Parents: b4e5c55
Author: Chen Liang <cliang@apache.org>
Authored: Mon May 22 10:20:04 2017 -0700
Committer: Chen Liang <cliang@apache.org>
Committed: Mon May 22 10:20:04 2017 -0700

----------------------------------------------------------------------
 .../apache/hadoop/scm/XceiverClientManager.java | 45 ++++++++++----------
 1 file changed, 23 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b72ac927/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java
index 3d2a913..637268b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/XceiverClientManager.java
@@ -105,28 +105,29 @@ public class XceiverClientManager {
     Preconditions.checkArgument(pipeline.getMachines() != null);
     Preconditions.checkArgument(!pipeline.getMachines().isEmpty());
     String containerName = pipeline.getContainerName();
-    XceiverClientWithAccessInfo info = openClient.getIfPresent(containerName);
-
-    if (info != null) {
-      // we do have this connection, add reference and return
-      info.incrementReference();
-      return info.getXceiverClient();
-    } else {
-      // connection not found, create new, add reference and return
-      final XceiverClientSpi xceiverClient = useRatis?
-          XceiverClientRatis.newXceiverClientRatis(pipeline, conf)
-          : new XceiverClient(pipeline, conf);
-      try {
-        xceiverClient.connect();
-      } catch (Exception e) {
-        throw new IOException("Exception connecting XceiverClient.", e);
-      }
-      info = new XceiverClientWithAccessInfo(xceiverClient);
-      info.incrementReference();
-      synchronized (openClient) {
+    synchronized(openClient) {
+      XceiverClientWithAccessInfo info =
+          openClient.getIfPresent(containerName);
+
+      if (info != null) {
+        // we do have this connection, add reference and return
+        info.incrementReference();
+        return info.getXceiverClient();
+      } else {
+        // connection not found, create new, add reference and return
+        final XceiverClientSpi xceiverClient = useRatis ?
+            XceiverClientRatis.newXceiverClientRatis(pipeline, conf)
+            : new XceiverClient(pipeline, conf);
+        try {
+          xceiverClient.connect();
+        } catch (Exception e) {
+          throw new IOException("Exception connecting XceiverClient.", e);
+        }
+        info = new XceiverClientWithAccessInfo(xceiverClient);
+        info.incrementReference();
         openClient.put(containerName, info);
+        return xceiverClient;
       }
-      return xceiverClient;
     }
   }
 
@@ -141,9 +142,9 @@ public class XceiverClientManager {
     XceiverClientWithAccessInfo info;
     synchronized (openClient) {
       info = openClient.getIfPresent(containerName);
+      Preconditions.checkNotNull(info);
+      info.decrementReference();
     }
-    Preconditions.checkNotNull(info);
-    info.decrementReference();
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message