Selaa lähdekoodia

Revert "AMBARI-17651. Restart indicator is not shown after modifying the configs (dlysnichenko)"

This reverts commit 18f0a8f61b86ce4fa021333f36b3bdabf85b2a9f.
Jonathan Hurley 9 vuotta sitten
vanhempi
commit
0ee10290fd

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java

@@ -473,7 +473,7 @@ public class HeartBeatHandler {
           now));
     }
 
-    configHelper.invalidateStaleConfigsCache(hostname, null);
+    configHelper.invalidateStaleConfigsCache(hostname);
 
     response.setStatusCommands(cmds);
 

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

@@ -696,9 +696,9 @@ public class ConfigGroupResourceProvider extends
         LOG.warn("Could not determine service name for config group {}, service config version not created",
             configGroup.getId());
       }
-      getManagementController().getConfigHelper().invalidateStaleConfigsCache(cluster.getDesiredConfigs());
     }
 
+    getManagementController().getConfigHelper().invalidateStaleConfigsCache();
   }
 
   @SuppressWarnings("unchecked")

+ 22 - 47
ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java

@@ -33,7 +33,6 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 
 import org.apache.ambari.annotations.TransactionalLock;
@@ -465,7 +464,7 @@ public class ConfigHelper {
    *
    * @param sch
    *          the SCH to calcualte config staleness for (not {@code null}).
-   * @param requestDesiredConfigs
+   * @param desiredConfigs
    *          the desired configurations for the cluster. Obtaining these can be
    *          expensive and since this method operates on SCH's, it could be
    *          called 10,000's of times when generating cluster/host responses.
@@ -475,45 +474,26 @@ public class ConfigHelper {
    *
    * @return <code>true</code> if the actual configs are stale
    */
-  public boolean isStaleConfigs(ServiceComponentHost sch, Map<String, DesiredConfig> requestDesiredConfigs)
+  public boolean isStaleConfigs(ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs)
       throws AmbariException {
     Boolean stale = null;
-    Lock readLock = transactionLocks.getLock(LockArea.STALE_CONFIG_CACHE).readLock();
-    readLock.lock();
-    try {
-      // try the cache
-      if (STALE_CONFIGS_CACHE_ENABLED) {
-        stale = staleConfigsCache.getIfPresent(sch);
-      }
 
-      if (stale == null) {
-        /*
-         prefer staleConfigCacheDesiredConfigs(they are supposed to be passed from thread that updated configs) to avoid
-         population staleConfigsCache with stale data in case current thread have stale EL caches(this can happen during
-         parallel requests)
-         */
-        Map<String, DesiredConfig> desiredConfigs = staleConfigCacheDesiredConfigs != null ? staleConfigCacheDesiredConfigs : requestDesiredConfigs;
-        stale = calculateIsStaleConfigs(sch, desiredConfigs);
-        staleConfigsCache.put(sch, stale);
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("Cache configuration staleness for host {} and component {} as {}",
-              sch.getHostName(), sch.getServiceComponentName(), stale);
-        }
-      }
-      return stale;
-    } finally {
-      readLock.unlock();
+    // try the cache
+    if (STALE_CONFIGS_CACHE_ENABLED) {
+      stale = staleConfigsCache.getIfPresent(sch);
     }
 
+    if (stale == null) {
+      stale = calculateIsStaleConfigs(sch, desiredConfigs);
+      staleConfigsCache.put(sch, stale);
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Cache configuration staleness for host {} and component {} as {}",
+            sch.getHostName(), sch.getServiceComponentName(), stale);
+      }
+    }
+    return stale;
   }
 
-  /**
-   * Every request that updates configs or configs-groups must invalidate staleConfigCache and update this filed
-   * with its own updated desiredConfigs(they must be passed form updater request) to avoid any issues with EL caches
-   * during parallel requests.
-   */
-  private Map<String, DesiredConfig> staleConfigCacheDesiredConfigs = null;
-
   /**
    * Invalidates the stale configuration cache for all
    * {@link ServiceComponentHost}s for the given host. This will execute the
@@ -523,13 +503,12 @@ public class ConfigHelper {
    * cluster global locks already acquired.
    *
    * @param hostname
-   * @param desiredConfigs desired cluster configs that will be used for configuration invalidation
    */
-  public void invalidateStaleConfigsCache(String hostname, Map<String, DesiredConfig> desiredConfigs) {
+  public void invalidateStaleConfigsCache(String hostname) {
     try {
       for (Cluster cluster : clusters.getClustersForHost(hostname)) {
         List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname);
-        Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(serviceComponentHosts, desiredConfigs);
+        Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(serviceComponentHosts);
         cacheInvalidationExecutor.execute(invalidationRunnable);
       }
     } catch (AmbariException e) {
@@ -544,8 +523,8 @@ public class ConfigHelper {
    * performed on a separate thread. This way, it won't interfere with any
    * cluster global locks already acquired.
    */
-  public void invalidateStaleConfigsCache(Map<String, DesiredConfig> desiredConfigs) {
-    Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(desiredConfigs);
+  public void invalidateStaleConfigsCache() {
+    Runnable invalidationRunnable = new StaleConfigInvalidationRunnable();
     cacheInvalidationExecutor.execute(invalidationRunnable);
   }
 
@@ -557,8 +536,8 @@ public class ConfigHelper {
    * performed on a separate thread. This way, it won't interfere with any
    * cluster global locks already acquired.
    */
-  public void invalidateStaleConfigsCache(ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs) {
-    Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(Collections.singletonList(sch), desiredConfigs);
+  public void invalidateStaleConfigsCache(ServiceComponentHost sch) {
+    Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(Collections.singletonList(sch));
     cacheInvalidationExecutor.execute(invalidationRunnable);
   }
 
@@ -1352,15 +1331,13 @@ public class ConfigHelper {
   private final class StaleConfigInvalidationRunnable implements Runnable {
 
     private final List<ServiceComponentHost> m_keysToInvalidate;
-    private final Map<String, DesiredConfig> m_desiredConfigs;
 
     /**
      * Constructor.
      *
      */
-    private StaleConfigInvalidationRunnable(Map<String, DesiredConfig> desiredConfigs) {
+    private StaleConfigInvalidationRunnable() {
       m_keysToInvalidate = null;
-      m_desiredConfigs = desiredConfigs;
     }
 
     /**
@@ -1369,9 +1346,8 @@ public class ConfigHelper {
      * @param keysToInvalidate
      *          the keys to invalidate in the cache.
      */
-    private StaleConfigInvalidationRunnable(List<ServiceComponentHost> keysToInvalidate, Map<String, DesiredConfig> desiredConfigs) {
+    private StaleConfigInvalidationRunnable(List<ServiceComponentHost> keysToInvalidate) {
       m_keysToInvalidate = keysToInvalidate;
-      m_desiredConfigs = desiredConfigs;
     }
 
     /**
@@ -1382,7 +1358,6 @@ public class ConfigHelper {
       ReadWriteLock lock = transactionLocks.getLock(LockArea.STALE_CONFIG_CACHE);
       lock.writeLock().lock();
       try {
-        ConfigHelper.this.staleConfigCacheDesiredConfigs = m_desiredConfigs;
         if (null == m_keysToInvalidate || m_keysToInvalidate.isEmpty()) {
           staleConfigsCache.invalidateAll();
         } else {

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

@@ -534,7 +534,7 @@ public class ClusterImpl implements Cluster {
             + configGroup.getTag());
       } else {
         clusterConfigGroups.put(configGroup.getId(), configGroup);
-        configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
+        configHelper.invalidateStaleConfigsCache();
       }
 
     } finally {
@@ -646,7 +646,7 @@ public class ClusterImpl implements Cluster {
 
       configGroup.delete();
       clusterConfigGroups.remove(id);
-      configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
+      configHelper.invalidateStaleConfigsCache();
     } finally {
       clusterGlobalLock.writeLock().unlock();
     }
@@ -2337,7 +2337,7 @@ public class ClusterImpl implements Cluster {
       ServiceConfigVersionResponse serviceConfigVersionResponse = applyConfigs(
           configs, user, serviceConfigVersionNote);
 
-      configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
+      configHelper.invalidateStaleConfigsCache();
       return serviceConfigVersionResponse;
     } finally {
       clusterGlobalLock.writeLock().unlock();
@@ -2556,7 +2556,7 @@ public class ClusterImpl implements Cluster {
     try {
       ServiceConfigVersionResponse serviceConfigVersionResponse = applyServiceConfigVersion(
           serviceName, version, user, note);
-      configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
+      configHelper.invalidateStaleConfigsCache();
       return serviceConfigVersionResponse;
     } finally {
       clusterGlobalLock.writeLock().unlock();

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

@@ -1797,7 +1797,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
       if (desiredStateEntity != null) {
         desiredStateEntity.setRestartRequired(restartRequired);
         saveComponentDesiredStateEntityIfPersisted();
-        helper.invalidateStaleConfigsCache(this, null);
+        helper.invalidateStaleConfigsCache(this);
       } else {
         LOG.warn("Setting a member on an entity object that may have been " +
           "previously deleted, serviceName = " + getServiceName() + ", " +

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java

@@ -515,7 +515,7 @@ public class ConfigGroupResourceProviderTest {
       }
     });
     expect(managementController.getConfigHelper()).andReturn(configHelper).once();
-    configHelper.invalidateStaleConfigsCache(null);
+    configHelper.invalidateStaleConfigsCache();
     expectLastCall().once();
 
     replay(managementController, clusters, cluster,

+ 4 - 4
ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java

@@ -737,7 +737,7 @@ public class ConfigHelperTest {
       hc2.setDefaultVersionTag("version1");
       schReturn.put("flume-conf", hc2);
       // invalidate cache to test new sch
-      configHelper.invalidateStaleConfigsCache(null);
+      configHelper.invalidateStaleConfigsCache();
       // Cluster level same configs
       Assert.assertFalse(configHelper.isStaleConfigs(sch, null));
 
@@ -757,7 +757,7 @@ public class ConfigHelperTest {
       hc3.setDefaultVersionTag("version1");
       hc3.getConfigGroupOverrides().put(1l, "FLUME1");
       schReturn.put("flume-conf", hc3);
-      configHelper.invalidateStaleConfigsCache(null);
+      configHelper.invalidateStaleConfigsCache();
 
       // version1 and FLUME1 - stale=false
       Assert.assertFalse(configHelper.isStaleConfigs(sch, null));
@@ -766,7 +766,7 @@ public class ConfigHelperTest {
       hc4.setDefaultVersionTag("version1");
       hc4.getConfigGroupOverrides().put(1l, "FLUME2");
       schReturn.put("flume-conf", hc4);
-      configHelper.invalidateStaleConfigsCache(null);
+      configHelper.invalidateStaleConfigsCache();
 
       // version1 and FLUME2 - stale=true
       Assert.assertTrue(configHelper.isStaleConfigs(sch, null));
@@ -775,7 +775,7 @@ public class ConfigHelperTest {
       hc5.setDefaultVersionTag("version3");
       hc5.getConfigGroupOverrides().put(1l, "FLUME1");
       schReturn.put("flume-conf", hc5);
-      configHelper.invalidateStaleConfigsCache(null);
+      configHelper.invalidateStaleConfigsCache();
 
       // version3 and FLUME1 - stale=true
       Assert.assertTrue(configHelper.isStaleConfigs(sch, null));