You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2016/07/11 15:54:48 UTC
[1/2] ambari git commit: AMBARI-17651. Restart indicator is not shown
after modifying the configs (dlysnichenko)
Repository: ambari
Updated Branches:
refs/heads/branch-2.4 ad11d50b0 -> 18f0a8f61
refs/heads/trunk 6c03848a7 -> 31e2c30b9
AMBARI-17651. Restart indicator is not shown after modifying the configs (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/18f0a8f6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/18f0a8f6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/18f0a8f6
Branch: refs/heads/branch-2.4
Commit: 18f0a8f61b86ce4fa021333f36b3bdabf85b2a9f
Parents: ad11d50
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Mon Jul 11 18:53:12 2016 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Mon Jul 11 18:54:21 2016 +0300
----------------------------------------------------------------------
.../ambari/server/agent/HeartBeatHandler.java | 2 +-
.../internal/ConfigGroupResourceProvider.java | 2 +-
.../ambari/server/state/ConfigHelper.java | 69 +++++++++++++-------
.../server/state/cluster/ClusterImpl.java | 8 +--
.../svccomphost/ServiceComponentHostImpl.java | 2 +-
.../ConfigGroupResourceProviderTest.java | 2 +-
.../ambari/server/state/ConfigHelperTest.java | 8 +--
7 files changed, 59 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/18f0a8f6/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
index 94a8fe0..f9ce8e6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
@@ -473,7 +473,7 @@ public class HeartBeatHandler {
now));
}
- configHelper.invalidateStaleConfigsCache(hostname);
+ configHelper.invalidateStaleConfigsCache(hostname, null);
response.setStatusCommands(cmds);
http://git-wip-us.apache.org/repos/asf/ambari/blob/18f0a8f6/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 d4e3828..3ba8e69 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
@@ -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")
http://git-wip-us.apache.org/repos/asf/ambari/blob/18f0a8f6/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
index 46a3f3e..e533315 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
@@ -33,6 +33,7 @@ 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;
@@ -464,7 +465,7 @@ public class ConfigHelper {
*
* @param sch
* the SCH to calcualte config staleness for (not {@code null}).
- * @param desiredConfigs
+ * @param requestDesiredConfigs
* 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.
@@ -474,27 +475,46 @@ public class ConfigHelper {
*
* @return <code>true</code> if the actual configs are stale
*/
- public boolean isStaleConfigs(ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs)
+ public boolean isStaleConfigs(ServiceComponentHost sch, Map<String, DesiredConfig> requestDesiredConfigs)
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);
+ }
- // 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);
+ 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();
}
- 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
* invalidation on a separate thread. The thread will attempt to acquire the
@@ -503,12 +523,13 @@ 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) {
+ public void invalidateStaleConfigsCache(String hostname, Map<String, DesiredConfig> desiredConfigs) {
try {
for (Cluster cluster : clusters.getClustersForHost(hostname)) {
List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname);
- Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(serviceComponentHosts);
+ Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(serviceComponentHosts, desiredConfigs);
cacheInvalidationExecutor.execute(invalidationRunnable);
}
} catch (AmbariException e) {
@@ -523,8 +544,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() {
- Runnable invalidationRunnable = new StaleConfigInvalidationRunnable();
+ public void invalidateStaleConfigsCache(Map<String, DesiredConfig> desiredConfigs) {
+ Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(desiredConfigs);
cacheInvalidationExecutor.execute(invalidationRunnable);
}
@@ -536,8 +557,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) {
- Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(Collections.singletonList(sch));
+ public void invalidateStaleConfigsCache(ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs) {
+ Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(Collections.singletonList(sch), desiredConfigs);
cacheInvalidationExecutor.execute(invalidationRunnable);
}
@@ -1331,13 +1352,15 @@ 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() {
+ private StaleConfigInvalidationRunnable(Map<String, DesiredConfig> desiredConfigs) {
m_keysToInvalidate = null;
+ m_desiredConfigs = desiredConfigs;
}
/**
@@ -1346,8 +1369,9 @@ public class ConfigHelper {
* @param keysToInvalidate
* the keys to invalidate in the cache.
*/
- private StaleConfigInvalidationRunnable(List<ServiceComponentHost> keysToInvalidate) {
+ private StaleConfigInvalidationRunnable(List<ServiceComponentHost> keysToInvalidate, Map<String, DesiredConfig> desiredConfigs) {
m_keysToInvalidate = keysToInvalidate;
+ m_desiredConfigs = desiredConfigs;
}
/**
@@ -1358,6 +1382,7 @@ 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 {
http://git-wip-us.apache.org/repos/asf/ambari/blob/18f0a8f6/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index fdb997b..53059dc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/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();
+ configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
}
} finally {
@@ -646,7 +646,7 @@ public class ClusterImpl implements Cluster {
configGroup.delete();
clusterConfigGroups.remove(id);
- configHelper.invalidateStaleConfigsCache();
+ configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
} finally {
clusterGlobalLock.writeLock().unlock();
}
@@ -2337,7 +2337,7 @@ public class ClusterImpl implements Cluster {
ServiceConfigVersionResponse serviceConfigVersionResponse = applyConfigs(
configs, user, serviceConfigVersionNote);
- configHelper.invalidateStaleConfigsCache();
+ configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
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();
+ configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
return serviceConfigVersionResponse;
} finally {
clusterGlobalLock.writeLock().unlock();
http://git-wip-us.apache.org/repos/asf/ambari/blob/18f0a8f6/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index 666111b..78f3751 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/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);
+ helper.invalidateStaleConfigsCache(this, null);
} else {
LOG.warn("Setting a member on an entity object that may have been " +
"previously deleted, serviceName = " + getServiceName() + ", " +
http://git-wip-us.apache.org/repos/asf/ambari/blob/18f0a8f6/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
index dc8017a..2a4b949 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
+++ b/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();
+ configHelper.invalidateStaleConfigsCache(null);
expectLastCall().once();
replay(managementController, clusters, cluster,
http://git-wip-us.apache.org/repos/asf/ambari/blob/18f0a8f6/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
index 0ff143c..73fb6ca 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
+++ b/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();
+ configHelper.invalidateStaleConfigsCache(null);
// 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();
+ configHelper.invalidateStaleConfigsCache(null);
// 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();
+ configHelper.invalidateStaleConfigsCache(null);
// 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();
+ configHelper.invalidateStaleConfigsCache(null);
// version3 and FLUME1 - stale=true
Assert.assertTrue(configHelper.isStaleConfigs(sch, null));
[2/2] ambari git commit: AMBARI-17651. Restart indicator is not shown
after modifying the configs (dlysnichenko)
Posted by dm...@apache.org.
AMBARI-17651. Restart indicator is not shown after modifying the configs (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/31e2c30b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/31e2c30b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/31e2c30b
Branch: refs/heads/trunk
Commit: 31e2c30b9cae7bdf4cc99bca27f759a66ae1738c
Parents: 6c03848
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Mon Jul 11 18:53:12 2016 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Mon Jul 11 18:54:34 2016 +0300
----------------------------------------------------------------------
.../ambari/server/agent/HeartBeatHandler.java | 2 +-
.../internal/ConfigGroupResourceProvider.java | 2 +-
.../ambari/server/state/ConfigHelper.java | 69 +++++++++++++-------
.../server/state/cluster/ClusterImpl.java | 8 +--
.../svccomphost/ServiceComponentHostImpl.java | 2 +-
.../ConfigGroupResourceProviderTest.java | 2 +-
.../ambari/server/state/ConfigHelperTest.java | 8 +--
7 files changed, 59 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/31e2c30b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
index 94a8fe0..f9ce8e6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
@@ -473,7 +473,7 @@ public class HeartBeatHandler {
now));
}
- configHelper.invalidateStaleConfigsCache(hostname);
+ configHelper.invalidateStaleConfigsCache(hostname, null);
response.setStatusCommands(cmds);
http://git-wip-us.apache.org/repos/asf/ambari/blob/31e2c30b/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 d4e3828..3ba8e69 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
@@ -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")
http://git-wip-us.apache.org/repos/asf/ambari/blob/31e2c30b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
index 46a3f3e..e533315 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
@@ -33,6 +33,7 @@ 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;
@@ -464,7 +465,7 @@ public class ConfigHelper {
*
* @param sch
* the SCH to calcualte config staleness for (not {@code null}).
- * @param desiredConfigs
+ * @param requestDesiredConfigs
* 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.
@@ -474,27 +475,46 @@ public class ConfigHelper {
*
* @return <code>true</code> if the actual configs are stale
*/
- public boolean isStaleConfigs(ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs)
+ public boolean isStaleConfigs(ServiceComponentHost sch, Map<String, DesiredConfig> requestDesiredConfigs)
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);
+ }
- // 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);
+ 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();
}
- 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
* invalidation on a separate thread. The thread will attempt to acquire the
@@ -503,12 +523,13 @@ 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) {
+ public void invalidateStaleConfigsCache(String hostname, Map<String, DesiredConfig> desiredConfigs) {
try {
for (Cluster cluster : clusters.getClustersForHost(hostname)) {
List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname);
- Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(serviceComponentHosts);
+ Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(serviceComponentHosts, desiredConfigs);
cacheInvalidationExecutor.execute(invalidationRunnable);
}
} catch (AmbariException e) {
@@ -523,8 +544,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() {
- Runnable invalidationRunnable = new StaleConfigInvalidationRunnable();
+ public void invalidateStaleConfigsCache(Map<String, DesiredConfig> desiredConfigs) {
+ Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(desiredConfigs);
cacheInvalidationExecutor.execute(invalidationRunnable);
}
@@ -536,8 +557,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) {
- Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(Collections.singletonList(sch));
+ public void invalidateStaleConfigsCache(ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs) {
+ Runnable invalidationRunnable = new StaleConfigInvalidationRunnable(Collections.singletonList(sch), desiredConfigs);
cacheInvalidationExecutor.execute(invalidationRunnable);
}
@@ -1331,13 +1352,15 @@ 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() {
+ private StaleConfigInvalidationRunnable(Map<String, DesiredConfig> desiredConfigs) {
m_keysToInvalidate = null;
+ m_desiredConfigs = desiredConfigs;
}
/**
@@ -1346,8 +1369,9 @@ public class ConfigHelper {
* @param keysToInvalidate
* the keys to invalidate in the cache.
*/
- private StaleConfigInvalidationRunnable(List<ServiceComponentHost> keysToInvalidate) {
+ private StaleConfigInvalidationRunnable(List<ServiceComponentHost> keysToInvalidate, Map<String, DesiredConfig> desiredConfigs) {
m_keysToInvalidate = keysToInvalidate;
+ m_desiredConfigs = desiredConfigs;
}
/**
@@ -1358,6 +1382,7 @@ 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 {
http://git-wip-us.apache.org/repos/asf/ambari/blob/31e2c30b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index fdb997b..53059dc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/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();
+ configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
}
} finally {
@@ -646,7 +646,7 @@ public class ClusterImpl implements Cluster {
configGroup.delete();
clusterConfigGroups.remove(id);
- configHelper.invalidateStaleConfigsCache();
+ configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
} finally {
clusterGlobalLock.writeLock().unlock();
}
@@ -2337,7 +2337,7 @@ public class ClusterImpl implements Cluster {
ServiceConfigVersionResponse serviceConfigVersionResponse = applyConfigs(
configs, user, serviceConfigVersionNote);
- configHelper.invalidateStaleConfigsCache();
+ configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
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();
+ configHelper.invalidateStaleConfigsCache(getDesiredConfigs());
return serviceConfigVersionResponse;
} finally {
clusterGlobalLock.writeLock().unlock();
http://git-wip-us.apache.org/repos/asf/ambari/blob/31e2c30b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index 666111b..78f3751 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/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);
+ helper.invalidateStaleConfigsCache(this, null);
} else {
LOG.warn("Setting a member on an entity object that may have been " +
"previously deleted, serviceName = " + getServiceName() + ", " +
http://git-wip-us.apache.org/repos/asf/ambari/blob/31e2c30b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
index dc8017a..2a4b949 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
+++ b/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();
+ configHelper.invalidateStaleConfigsCache(null);
expectLastCall().once();
replay(managementController, clusters, cluster,
http://git-wip-us.apache.org/repos/asf/ambari/blob/31e2c30b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
index 0ff143c..73fb6ca 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
+++ b/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();
+ configHelper.invalidateStaleConfigsCache(null);
// 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();
+ configHelper.invalidateStaleConfigsCache(null);
// 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();
+ configHelper.invalidateStaleConfigsCache(null);
// 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();
+ configHelper.invalidateStaleConfigsCache(null);
// version3 and FLUME1 - stale=true
Assert.assertTrue(configHelper.isStaleConfigs(sch, null));