ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject ambari git commit: AMBARI-15166. Cluster deadlock when calling create hosts api concurrently with host registration.(vbrodetskyi)
Date Wed, 02 Mar 2016 09:59:09 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 267d60778 -> 1a889a439


AMBARI-15166. Cluster deadlock when calling create hosts api concurrently with host registration.(vbrodetskyi)


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

Branch: refs/heads/branch-2.2
Commit: 1a889a4396c94b770206c540fe73b6b0ab0356be
Parents: 267d607
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Wed Mar 2 11:56:06 2016 +0200
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Wed Mar 2 11:56:06 2016 +0200

----------------------------------------------------------------------
 .../server/state/cluster/ClustersImpl.java      | 58 +++++++++-----------
 1 file changed, 26 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1a889a43/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index d5a4954..46dd49d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -18,20 +18,10 @@
 
 package org.apache.ambari.server.state.cluster;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import javax.persistence.RollbackException;
-
+import com.google.common.collect.Sets;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
 import org.apache.ambari.server.DuplicateResourceException;
@@ -56,7 +46,6 @@ import org.apache.ambari.server.orm.dao.ResourceTypeDAO;
 import org.apache.ambari.server.orm.dao.ServiceConfigDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.dao.TopologyHostRequestDAO;
-import org.apache.ambari.server.orm.dao.TopologyHostTaskDAO;
 import org.apache.ambari.server.orm.dao.TopologyLogicalTaskDAO;
 import org.apache.ambari.server.orm.dao.TopologyRequestDAO;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
@@ -91,10 +80,18 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.security.core.GrantedAuthority;
 
-import com.google.common.collect.Sets;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.persist.Transactional;
+import javax.persistence.RollbackException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 @Singleton
 public class ClustersImpl implements Clusters {
@@ -346,20 +343,17 @@ public class ClustersImpl implements Clusters {
   public Set<Cluster> getClustersForHost(String hostname)
       throws AmbariException {
     checkLoaded();
-    r.lock();
-    try {
-      if(!hostClusterMap.containsKey(hostname)){
-            throw new HostNotFoundException(hostname);
-      }
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Looking up clusters for hostname"
-            + ", hostname=" + hostname
-            + ", mappedClusters=" + hostClusterMap.get(hostname).size());
-      }
-      return Collections.unmodifiableSet(hostClusterMap.get(hostname));
-    } finally {
-      r.unlock();
+    Set<Cluster> clusters = hostClusterMap.get(hostname);
+    if(clusters == null){
+      throw new HostNotFoundException(hostname);
     }
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Looking up clusters for hostname"
+          + ", hostname=" + hostname
+          + ", mappedClusters=" + clusters.size());
+    }
+    return Collections.unmodifiableSet(clusters);
+
   }
 
   @Override


Mime
View raw message