ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject ambari git commit: AMBARI-11744. Ambari Server deadlocks when adding service / adding host. (swagle)
Date Sat, 06 Jun 2015 22:43:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.0-maint [created] d9cffc309


AMBARI-11744. Ambari Server deadlocks when adding service / adding host. (swagle)


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

Branch: refs/heads/branch-2.0-maint
Commit: d9cffc309a55861bf6cd70401afed6889dd42ea4
Parents: 7c439a2
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Fri Jun 5 20:33:33 2015 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Fri Jun 5 20:33:33 2015 -0700

----------------------------------------------------------------------
 .../internal/ConfigGroupResourceProvider.java   |   4 +-
 .../state/configgroup/ConfigGroupImpl.java      | 113 ++++++++++---------
 2 files changed, 61 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d9cffc30/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
index 3fcb84b..f4893cd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
@@ -523,9 +523,7 @@ public class ConfigGroupResourceProvider extends
     return configGroupResponses;
   }
 
-  private synchronized void updateConfigGroups
-    (Set<ConfigGroupRequest> requests) throws AmbariException {
-
+  private synchronized void updateConfigGroups (Set<ConfigGroupRequest> requests) throws
AmbariException {
     if (requests.isEmpty()) {
       LOG.warn("Received an empty requests set");
       return;

http://git-wip-us.apache.org/repos/asf/ambari/blob/d9cffc30/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
index 9ec0370..ea3c406 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
@@ -312,18 +312,23 @@ public class ConfigGroupImpl implements ConfigGroup {
 
   @Override
   public void persist() {
-    readWriteLock.writeLock().lock();
+    cluster.getClusterGlobalLock().writeLock().lock();
     try {
-      if (!isPersisted) {
-        persistEntities();
-        refresh();
-        cluster.refresh();
-        isPersisted = true;
-      } else {
-        saveIfPersisted();
+      readWriteLock.writeLock().lock();
+      try {
+        if (!isPersisted) {
+          persistEntities();
+          refresh();
+          cluster.refresh();
+          isPersisted = true;
+        } else {
+          saveIfPersisted();
+        }
+      } finally {
+        readWriteLock.writeLock().unlock();
       }
     } finally {
-      readWriteLock.writeLock().unlock();
+      cluster.getClusterGlobalLock().writeLock().unlock();
     }
   }
 
@@ -413,19 +418,11 @@ public class ConfigGroupImpl implements ConfigGroup {
             clusterConfigEntity.setAttributes(gson.toJson(config.getPropertiesAttributes()));
           }
           clusterConfigEntity.setTimestamp(System.currentTimeMillis());
-
-
-          // TODO: Is locking necessary and functional ?
-          cluster.getClusterGlobalLock().writeLock().lock();
-          try {
-            clusterDAO.createConfig(clusterConfigEntity);
-            clusterEntity.getClusterConfigEntities().add(clusterConfigEntity);
-            cluster.addConfig(config);
-            clusterDAO.merge(clusterEntity);
-            cluster.refresh();
-          } finally {
-            cluster.getClusterGlobalLock().writeLock().unlock();
-          }
+          clusterDAO.createConfig(clusterConfigEntity);
+          clusterEntity.getClusterConfigEntities().add(clusterConfigEntity);
+          cluster.addConfig(config);
+          clusterDAO.merge(clusterEntity);
+          cluster.refresh();
         }
 
         ConfigGroupConfigMappingEntity configMappingEntity =
@@ -460,15 +457,20 @@ public class ConfigGroupImpl implements ConfigGroup {
   @Override
   @Transactional
   public void delete() {
-    readWriteLock.writeLock().lock();
+    cluster.getClusterGlobalLock().writeLock().lock();
     try {
-      configGroupConfigMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
-      configGroupHostMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
-      configGroupDAO.removeByPK(configGroupEntity.getGroupId());
-      cluster.refresh();
-      isPersisted = false;
+      readWriteLock.writeLock().lock();
+      try {
+        configGroupConfigMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
+        configGroupHostMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
+        configGroupDAO.removeByPK(configGroupEntity.getGroupId());
+        cluster.refresh();
+        isPersisted = false;
+      } finally {
+        readWriteLock.writeLock().unlock();
+      }
     } finally {
-      readWriteLock.writeLock().unlock();
+      cluster.getClusterGlobalLock().writeLock().unlock();
     }
   }
 
@@ -513,35 +515,40 @@ public class ConfigGroupImpl implements ConfigGroup {
 
   @Override
   public ConfigGroupResponse convertToResponse() throws AmbariException {
-    readWriteLock.readLock().lock();
+    cluster.getClusterGlobalLock().readLock().lock();
     try {
-      Set<Map<String, Object>> hostnames = new HashSet<Map<String, Object>>();
-      for (Host host : hosts.values()) {
-        Map<String, Object> hostMap = new HashMap<String, Object>();
-        hostMap.put("host_name", host.getHostName());
-        hostnames.add(hostMap);
-      }
+      readWriteLock.readLock().lock();
+      try {
+        Set<Map<String, Object>> hostnames = new HashSet<Map<String, Object>>();
+        for (Host host : hosts.values()) {
+          Map<String, Object> hostMap = new HashMap<String, Object>();
+          hostMap.put("host_name", host.getHostName());
+          hostnames.add(hostMap);
+        }
 
-      Set<Map<String, Object>> configObjMap = new HashSet<Map<String,
-        Object>>();
+        Set<Map<String, Object>> configObjMap = new HashSet<Map<String,
+          Object>>();
 
-      for (Config config : configurations.values()) {
-        Map<String, Object> configMap = new HashMap<String, Object>();
-        configMap.put(ConfigurationResourceProvider
-          .CONFIGURATION_CONFIG_TYPE_PROPERTY_ID, config.getType());
-        configMap.put(ConfigurationResourceProvider
-          .CONFIGURATION_CONFIG_TAG_PROPERTY_ID, config.getTag());
-        configObjMap.add(configMap);
-      }
+        for (Config config : configurations.values()) {
+          Map<String, Object> configMap = new HashMap<String, Object>();
+          configMap.put(ConfigurationResourceProvider
+            .CONFIGURATION_CONFIG_TYPE_PROPERTY_ID, config.getType());
+          configMap.put(ConfigurationResourceProvider
+            .CONFIGURATION_CONFIG_TAG_PROPERTY_ID, config.getTag());
+          configObjMap.add(configMap);
+        }
 
-      ConfigGroupResponse configGroupResponse = new ConfigGroupResponse(
-        configGroupEntity.getGroupId(), cluster.getClusterName(),
-        configGroupEntity.getGroupName(), configGroupEntity.getTag(),
-        configGroupEntity.getDescription(),
-        hostnames, configObjMap);
-      return configGroupResponse;
+        ConfigGroupResponse configGroupResponse = new ConfigGroupResponse(
+          configGroupEntity.getGroupId(), cluster.getClusterName(),
+          configGroupEntity.getGroupName(), configGroupEntity.getTag(),
+          configGroupEntity.getDescription(),
+          hostnames, configObjMap);
+        return configGroupResponse;
+      } finally {
+        readWriteLock.readLock().unlock();
+      }
     } finally {
-      readWriteLock.readLock().unlock();
+      cluster.getClusterGlobalLock().readLock().unlock();
     }
   }
 


Mime
View raw message