Skip to content

Commit 1b9ff45

Browse files
committedSep 29, 2024
Revert "[AMBARI-26076] Upgrade net.sf.ehcache to 3.10.0 (apache#3825)"
This reverts commit b6a3185.
1 parent 13aa0aa commit 1b9ff45

14 files changed

+497
-466
lines changed
 

‎ambari-server/pom.xml

+2-27
Original file line numberDiff line numberDiff line change
@@ -1367,10 +1367,6 @@
13671367
<groupId>org.codehaus.jackson</groupId>
13681368
<artifactId>jackson-mapper-asl</artifactId>
13691369
</exclusion>
1370-
<exclusion>
1371-
<groupId>javax.xml.bind</groupId>
1372-
<artifactId>jaxb-api</artifactId>
1373-
</exclusion>
13741370
</exclusions>
13751371
</dependency>
13761372
<dependency>
@@ -1665,30 +1661,9 @@
16651661
<artifactId>jackson-databind</artifactId>
16661662
</dependency>
16671663
<dependency>
1668-
<groupId>javax.xml.bind</groupId>
1669-
<artifactId>jaxb-api</artifactId>
1670-
<version>2.3.1</version>
1671-
</dependency>
1672-
<dependency>
1673-
<groupId>com.sun.istack</groupId>
1674-
<artifactId>istack-commons-runtime</artifactId>
1675-
<version>4.0.0</version>
1676-
</dependency>
1677-
<dependency>
1678-
<groupId>com.sun.xml.fastinfoset</groupId>
1679-
<artifactId>FastInfoset</artifactId>
1680-
<version>1.2.16</version>
1681-
</dependency>
1682-
<dependency>
1683-
<groupId>org.ehcache</groupId>
1664+
<groupId>net.sf.ehcache</groupId>
16841665
<artifactId>ehcache</artifactId>
1685-
<version>3.10.0</version>
1686-
<exclusions>
1687-
<exclusion>
1688-
<groupId>org.glassfish.jaxb</groupId>
1689-
<artifactId>jaxb-runtime</artifactId>
1690-
</exclusion>
1691-
</exclusions>
1666+
<version>2.10.0</version>
16921667
</dependency>
16931668
<dependency>
16941669
<groupId>com.nimbusds</groupId>

‎ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java

-16
Original file line numberDiff line numberDiff line change
@@ -2061,15 +2061,6 @@ public class Configuration {
20612061
public static final ConfigurationProperty<Integer> TIMELINE_METRICS_CACHE_IDLE_TIME = new ConfigurationProperty<>(
20622062
"server.timeline.metrics.cache.entry.idle.seconds", 1800);
20632063

2064-
/**
2065-
* Cache size in entry units that ambari metrics cache will hold.
2066-
*/
2067-
@Markdown(
2068-
relatedTo = "server.timeline.metrics.cache.disabled",
2069-
description = "cache size, in entries, that ambari metrics cache will hold.")
2070-
public static final ConfigurationProperty<Integer> TIMELINE_METRICS_CACHE_ENTRY_UNIT_SIZE = new ConfigurationProperty<>(
2071-
"server.timeline.metrics.cache.entry.entry.unit.size", 100);
2072-
20732064
/**
20742065
* The time, in {@link TimeUnit#MILLISECONDS}, that initial requests made to
20752066
* Ambari Metrics will wait while reading from the socket before timing out.
@@ -5278,13 +5269,6 @@ public int getMetricCacheIdleSeconds() {
52785269
return Integer.parseInt(getProperty(TIMELINE_METRICS_CACHE_IDLE_TIME));
52795270
}
52805271

5281-
/**
5282-
* Ambari metrics cache size.
5283-
*/
5284-
public int getMetricCacheEntryUnitSize() {
5285-
return Integer.parseInt(getProperty(TIMELINE_METRICS_CACHE_ENTRY_UNIT_SIZE));
5286-
}
5287-
52885272
/**
52895273
* Separate timeout settings for metrics cache.
52905274
* @return milliseconds

‎ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineAppMetricCacheKeySerializer.java

-78
This file was deleted.

‎ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCache.java

+68-35
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,35 @@
1818
package org.apache.ambari.server.controller.metrics.timeline.cache;
1919

2020
import java.io.IOException;
21+
import java.net.ConnectException;
2122
import java.net.SocketTimeoutException;
2223
import java.util.concurrent.atomic.AtomicInteger;
2324

2425
import org.apache.hadoop.metrics2.sink.timeline.TimelineMetrics;
25-
import org.ehcache.Cache;
26-
import org.ehcache.core.internal.statistics.DefaultStatisticsService;
27-
import org.ehcache.core.statistics.CacheStatistics;
28-
import org.ehcache.spi.loaderwriter.CacheLoadingException;
2926
import org.slf4j.Logger;
3027
import org.slf4j.LoggerFactory;
3128

32-
public class TimelineMetricCache {
33-
private final Cache<TimelineAppMetricCacheKey, TimelineMetricsCacheValue> cache;
34-
private final DefaultStatisticsService statisticsService;
35-
private final TimelineMetricCacheEntryFactory cacheEntryFactory;
36-
public static final String TIMELINE_METRIC_CACHE_INSTANCE_NAME = "timelineMetricCache";
29+
import net.sf.ehcache.CacheException;
30+
import net.sf.ehcache.Ehcache;
31+
import net.sf.ehcache.Element;
32+
import net.sf.ehcache.constructs.blocking.LockTimeoutException;
33+
import net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory;
34+
import net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache;
35+
import net.sf.ehcache.statistics.StatisticsGateway;
36+
37+
public class TimelineMetricCache extends UpdatingSelfPopulatingCache {
38+
3739
private final static Logger LOG = LoggerFactory.getLogger(TimelineMetricCache.class);
3840
private static AtomicInteger printCacheStatsCounter = new AtomicInteger(0);
3941

4042
/**
41-
* Creates a TimelineMetricCache.
43+
* Creates a SelfPopulatingCache.
4244
*
4345
* @param cache @Cache
44-
* @param cacheEntryFactory @CacheEntryFactory
45-
* @param statisticsService @DefaultStatisticsService
46+
* @param factory @CacheEntryFactory
4647
*/
47-
public TimelineMetricCache(Cache<TimelineAppMetricCacheKey, TimelineMetricsCacheValue> cache, TimelineMetricCacheEntryFactory cacheEntryFactory, DefaultStatisticsService statisticsService) {
48-
this.cache = cache;
49-
this.cacheEntryFactory = cacheEntryFactory;
50-
this.statisticsService = statisticsService;
48+
public TimelineMetricCache(Ehcache cache, UpdatingCacheEntryFactory factory) throws CacheException {
49+
super(cache, factory);
5150
}
5251

5352
/**
@@ -64,22 +63,26 @@ public TimelineMetrics getAppTimelineMetricsFromCache(TimelineAppMetricCacheKey
6463
// Make sure key is valid
6564
validateKey(key);
6665

67-
TimelineMetricsCacheValue value = null;
66+
Element element = null;
6867
try {
69-
value = cache.get(key);
70-
} catch (CacheLoadingException cle) {
71-
Throwable t = cle.getCause();
72-
if(t instanceof SocketTimeoutException) {
73-
throw new SocketTimeoutException(t.getMessage());
74-
}
75-
if(t instanceof IOException) {
76-
throw new IOException(t.getMessage());
68+
element = get(key);
69+
} catch (LockTimeoutException le) {
70+
// Ehcache masks the Socket Timeout to look as a LockTimeout
71+
Throwable t = le.getCause();
72+
if (t instanceof CacheException) {
73+
t = t.getCause();
74+
if (t instanceof SocketTimeoutException) {
75+
throw new SocketTimeoutException(t.getMessage());
76+
}
77+
if (t instanceof ConnectException) {
78+
throw new ConnectException(t.getMessage());
79+
}
7780
}
78-
throw cle;
7981
}
8082

8183
TimelineMetrics timelineMetrics = new TimelineMetrics();
82-
if (value != null) {
84+
if (element != null && element.getObjectValue() != null) {
85+
TimelineMetricsCacheValue value = (TimelineMetricsCacheValue) element.getObjectValue();
8386
if (LOG.isDebugEnabled()) {
8487
LOG.debug("Returning value from cache: {}", value);
8588
}
@@ -89,21 +92,51 @@ public TimelineMetrics getAppTimelineMetricsFromCache(TimelineAppMetricCacheKey
8992
if (LOG.isDebugEnabled()) {
9093
// Print stats every 100 calls - Note: Supported in debug mode only
9194
if (printCacheStatsCounter.getAndIncrement() == 0) {
92-
CacheStatistics cacheStatistics = statisticsService.getCacheStatistics(TIMELINE_METRIC_CACHE_INSTANCE_NAME);
93-
if(cacheStatistics == null) {
94-
LOG.warn("Cache statistics not available.");
95-
return timelineMetrics;
96-
}
97-
LOG.debug("Metrics cache stats => \n, Evictions = {}, Expired = {}, Hits = {}, Misses = {}, Hit ratio = {}, Puts = {}",
98-
cacheStatistics.getCacheEvictions(), cacheStatistics.getCacheExpirations(), cacheStatistics.getCacheHits(), cacheStatistics.getCacheMisses(), cacheStatistics.getCacheHitPercentage(), cacheStatistics.getCachePuts()
99-
);
95+
StatisticsGateway statistics = this.getStatistics();
96+
LOG.debug("Metrics cache stats => \n, Evictions = {}, Expired = {}, Hits = {}, Misses = {}, Hit ratio = {}, Puts = {}, Size in MB = {}",
97+
statistics.cacheEvictedCount(), statistics.cacheExpiredCount(), statistics.cacheHitCount(), statistics.cacheMissCount(), statistics.cacheHitRatio(),
98+
statistics.cachePutCount(), statistics.getLocalHeapSizeInBytes() / 1048576);
10099
} else {
101100
printCacheStatsCounter.compareAndSet(100, 0);
102101
}
103102
}
103+
104104
return timelineMetrics;
105105
}
106106

107+
/**
108+
* Set new time bounds on the cache key so that update can use the new
109+
* query window. We do this quietly which means regular get/update logic is
110+
* not invoked.
111+
*/
112+
@Override
113+
public Element get(Object key) throws LockTimeoutException {
114+
Element element = this.getQuiet(key);
115+
if (element != null) {
116+
if (LOG.isTraceEnabled()) {
117+
LOG.trace("key : {}", element.getObjectKey());
118+
LOG.trace("value : {}", element.getObjectValue());
119+
}
120+
121+
// Set new time boundaries on the key
122+
TimelineAppMetricCacheKey existingKey = (TimelineAppMetricCacheKey) element.getObjectKey();
123+
124+
LOG.debug("Existing temporal info: {} for : {}", existingKey.getTemporalInfo(), existingKey.getMetricNames());
125+
126+
TimelineAppMetricCacheKey newKey = (TimelineAppMetricCacheKey) key;
127+
existingKey.setTemporalInfo(newKey.getTemporalInfo());
128+
129+
LOG.debug("New temporal info: {} for : {}", newKey.getTemporalInfo(), existingKey.getMetricNames());
130+
131+
if (existingKey.getSpec() == null || !existingKey.getSpec().equals(newKey.getSpec())) {
132+
existingKey.setSpec(newKey.getSpec());
133+
LOG.debug("New spec: {} for : {}", newKey.getSpec(), existingKey.getMetricNames());
134+
}
135+
}
136+
137+
return super.get(key);
138+
}
139+
107140
private void validateKey(TimelineAppMetricCacheKey key) throws IllegalArgumentException {
108141
StringBuilder msg = new StringBuilder("Invalid metric key requested.");
109142
boolean throwException = false;

‎ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheCustomExpiry.java

-55
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.