ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-5345. Server Error: 500 status code received on GET method for API. (swagle)
Date Thu, 03 Apr 2014 20:55:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 2e7cb594f -> 99dbf3dbc


AMBARI-5345. Server Error: 500 status code received on GET method for API. (swagle)


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

Branch: refs/heads/trunk
Commit: 99dbf3dbcc5e275bf4b822ef96482c1b67190761
Parents: 2e7cb59
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Thu Apr 3 11:20:14 2014 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Thu Apr 3 11:20:50 2014 -0700

----------------------------------------------------------------------
 .../internal/AbstractProviderModule.java        | 34 ++++++++++----------
 1 file changed, 17 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/99dbf3db/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
index 23eafcb..4d358ec 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
@@ -51,6 +51,7 @@ import org.slf4j.LoggerFactory;
 
 import java.util.*;
 import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * An abstract provider module implementation.
@@ -66,13 +67,10 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
   private static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles",
"component_name");
   private static final String GANGLIA_SERVER                            = "GANGLIA_SERVER";
   private static final String PROPERTIES_CATEGORY = "properties";
-  private static final Map<Service.Type, String> serviceConfigVersions =
-    Collections.synchronizedMap(new HashMap<Service.Type, String>());
+  private static final Map<Service.Type, String> serviceConfigVersions = new ConcurrentHashMap<Service.Type,
String>();
   private static final Map<Service.Type, String> serviceConfigTypes = new HashMap<Service.Type,
String>();
-  private static final Map<Service.Type, Map<String, String[]>> serviceDesiredProperties
= new
-    HashMap<Service.Type, Map<String, String[]>>();
-  private static final Map<String, Service.Type> componentServiceMap = new
-    HashMap<String, Service.Type>();
+  private static final Map<Service.Type, Map<String, String[]>> serviceDesiredProperties
= new HashMap<Service.Type, Map<String, String[]>>();
+  private static final Map<String, Service.Type> componentServiceMap = new HashMap<String,
Service.Type>();
   
   private static final Map<String, Map<String, String[]>> jmxDesiredProperties
= new HashMap<String, Map<String,String[]>>();
   private volatile Map<String, String> clusterCoreSiteConfigVersionMap = new HashMap<String,
String>();
@@ -140,8 +138,8 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
   /**
    * JMX ports read from the configs
    */
-  private final Map<String, Map<String, String>> jmxPortMap = Collections
-    .synchronizedMap(new HashMap<String, Map<String, String>>());
+  private final Map<String, Map<String, String>> jmxPortMap =
+    new HashMap<String, Map<String, String>>();
 
   private volatile boolean initialized = false;
 
@@ -204,14 +202,14 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
   }
 
   @Override
-  public String getPort(String clusterName, String componentName) throws
-    SystemException {
-    Map<String,String> clusterJmxPorts = jmxPortMap.get(clusterName);
+  public String getPort(String clusterName, String componentName) throws SystemException
{
+    // Parent map need not be synchronized
+    Map<String, String> clusterJmxPorts = jmxPortMap.get(clusterName);
     if (clusterJmxPorts == null) {
       synchronized (jmxPortMap) {
         clusterJmxPorts = jmxPortMap.get(clusterName);
         if (clusterJmxPorts == null) {
-          clusterJmxPorts = new HashMap<String, String>();
+          clusterJmxPorts = new ConcurrentHashMap<String, String>();
           jmxPortMap.put(clusterName, clusterJmxPorts);
         }
       }
@@ -220,10 +218,13 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
     
     if (service != null) {
       try {
-        String currVersion = getDesiredConfigVersion(clusterName,
-          serviceConfigTypes.get(service));
-
+        String currVersion = getDesiredConfigVersion(clusterName, serviceConfigTypes.get(service));
         String oldVersion = serviceConfigVersions.get(service);
+
+        // We only update port map when a config version updates,
+        // Since concurrent thread access is expected we err on the side of
+        // performance with a ConcurrentHashMap and maybe get default/existing
+        // ports for a few calls.
         if (!currVersion.equals(oldVersion)) {
           serviceConfigVersions.put(service, currVersion);
           
@@ -232,8 +233,7 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
             serviceDesiredProperties.get(service));
           
           for (String compName : portMap.keySet()) {
-            clusterJmxPorts.put(compName, getPortString(portMap.get
-              (compName)));
+            clusterJmxPorts.put(compName, getPortString(portMap.get(compName)));
           }
         }
       } catch (Exception e) {


Mime
View raw message