Просмотр исходного кода

AMBARI-11433. Multiple perf issues with requests for host components. (mpapirkovskyy)

Myroslav Papirkovskyy 10 лет назад
Родитель
Сommit
3d8e9acc97

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java

@@ -442,7 +442,7 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
   }
 
   // Get the components for the given request.
-  private synchronized Set<ServiceComponentResponse> getComponents(
+  private Set<ServiceComponentResponse> getComponents(
       ServiceComponentRequest request) throws AmbariException {
     if (request.getClusterName() == null
         || request.getClusterName().isEmpty()) {

+ 0 - 9
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java

@@ -255,8 +255,6 @@ public class AlertsDAO {
       typedQuery.setMaxResults(request.Pagination.getPageSize());
     }
 
-    typedQuery = setQueryRefreshHint(typedQuery);
-
     return daoUtils.selectList(typedQuery);
   }
 
@@ -301,8 +299,6 @@ public class AlertsDAO {
       typedQuery.setMaxResults(request.Pagination.getPageSize());
     }
 
-    typedQuery = setQueryRefreshHint(typedQuery);
-
     return daoUtils.selectList(typedQuery);
   }
 
@@ -358,7 +354,6 @@ public class AlertsDAO {
         "AlertCurrentEntity.findByDefinitionId", AlertCurrentEntity.class);
 
     query.setParameter("definitionId", Long.valueOf(definitionId));
-    query = setQueryRefreshHint(query);
 
     return daoUtils.selectList(query);
   }
@@ -375,7 +370,6 @@ public class AlertsDAO {
         "AlertCurrentEntity.findByCluster", AlertCurrentEntity.class);
 
     query.setParameter("clusterId", Long.valueOf(clusterId));
-    query = setQueryRefreshHint(query);
 
     return daoUtils.selectList(query);
   }
@@ -502,7 +496,6 @@ public class AlertsDAO {
     query.setParameter("serviceName", serviceName);
     query.setParameter("inlist", EnumSet.of(Scope.ANY, Scope.SERVICE));
 
-    query = setQueryRefreshHint(query);
     return daoUtils.selectList(query);
   }
 
@@ -517,7 +510,6 @@ public class AlertsDAO {
     query.setParameter("hostName", hostName);
     query.setParameter("definitionName", alertName);
 
-    query = setQueryRefreshHint(query);
     return daoUtils.selectOne(query);
   }
 
@@ -778,7 +770,6 @@ public class AlertsDAO {
     query.setParameter("clusterId", Long.valueOf(clusterId));
     query.setParameter("definitionName", alertName);
 
-    query = setQueryRefreshHint(query);
     return daoUtils.selectOne(query);
   }
 

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java

@@ -61,7 +61,7 @@ public class ServiceComponentImpl implements ServiceComponent {
   private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
   private final boolean isClientComponent;
   private final boolean isMasterComponent;
-  boolean persisted = false;
+  volatile boolean persisted = false;
   @Inject
   private ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO;
   @Inject

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java

@@ -62,7 +62,7 @@ public class ServiceImpl implements Service {
   private static final Logger LOG =
       LoggerFactory.getLogger(ServiceImpl.class);
 
-  private boolean persisted = false;
+  private volatile boolean persisted = false;
   private final Cluster cluster;
   private Map<String, ServiceComponent> components;
   private final boolean isClientOnlyService;

+ 10 - 14
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java

@@ -164,12 +164,12 @@ public class ClusterImpl implements Cluster {
   /**
    * Map of existing config groups
    */
-  private Map<Long, ConfigGroup> clusterConfigGroups;
+  private volatile Map<Long, ConfigGroup> clusterConfigGroups;
 
   /**
    * Map of Request schedules for this cluster
    */
-  private Map<Long, RequestExecution> requestExecutions;
+  private volatile Map<Long, RequestExecution> requestExecutions;
 
   private final ReadWriteLock clusterGlobalLock = new ReentrantReadWriteLock();
 
@@ -485,22 +485,18 @@ public class ClusterImpl implements Cluster {
   @Override
   public Map<Long, ConfigGroup> getConfigGroupsByHostname(String hostname)
     throws AmbariException {
+    loadConfigGroups();
     Map<Long, ConfigGroup> configGroups = new HashMap<Long, ConfigGroup>();
-    Map<Long, ConfigGroup> configGroupMap = getConfigGroups();
 
     clusterGlobalLock.readLock().lock();
     try {
-      HostEntity hostEntity = hostDAO.findByName(hostname);
-      if (hostEntity != null) {
-        Set<ConfigGroupHostMapping> hostMappingEntities = configGroupHostMappingDAO.findByHostId(hostEntity.getHostId());
-
-        if (hostMappingEntities != null && !hostMappingEntities.isEmpty()) {
-          for (ConfigGroupHostMapping entity : hostMappingEntities) {
-            ConfigGroup configGroup = configGroupMap.get(entity.getConfigGroupId());
-            if (configGroup != null
-                && !configGroups.containsKey(configGroup.getId())) {
-              configGroups.put(configGroup.getId(), configGroup);
-            }
+      for (Entry<Long, ConfigGroup> groupEntry : clusterConfigGroups.entrySet()) {
+        Long id = groupEntry.getKey();
+        ConfigGroup group = groupEntry.getValue();
+        for (Host host : group.getHosts().values()) {
+          if (StringUtils.equals(hostname, host.getHostName())) {
+            configGroups.put(id, group);
+            break;
           }
         }
       }

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java

@@ -100,7 +100,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
 
   private final ServiceComponent serviceComponent;
   private final Host host;
-  private boolean persisted = false;
+  private volatile boolean persisted = false;
 
   @Inject
   HostComponentStateDAO hostComponentStateDAO;