diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/EntityGroupFSTimelineStore.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/EntityGroupFSTimelineStore.java index 9593a31..a31889f 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/EntityGroupFSTimelineStore.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/EntityGroupFSTimelineStore.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.timeline; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; @@ -166,11 +167,18 @@ protected void serviceInit(Configuration conf) throws Exception { unknownActiveMillis = unknownActiveSecs * 1000; LOG.info("Unknown apps will be treated as complete after {} seconds", unknownActiveSecs); + appCacheMaxSize = conf.getInt( YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_APP_CACHE_SIZE, YarnConfiguration .TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_APP_CACHE_SIZE_DEFAULT); + Preconditions + .checkArgument(appCacheMaxSize > 0, + "%s property value should be greater than zero", + YarnConfiguration + .TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_APP_CACHE_SIZE); LOG.info("Application cache size is {}", appCacheMaxSize); + cachedLogs = Collections.synchronizedMap( new LinkedHashMap( appCacheMaxSize + 1, 0.75f, true) { @@ -992,7 +1000,7 @@ void setCachedLogs(TimelineEntityGroupId groupId, EntityCacheItem cacheItem) { private TimelineStore getCachedStore(TimelineEntityGroupId groupId, List cacheItems) throws IOException { EntityCacheItem cacheItem; - synchronized (this.cachedLogs) { + synchronized (cachedLogs) { // Note that the content in the cache log storage may be stale. cacheItem = this.cachedLogs.get(groupId); if (cacheItem == null) { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/LevelDBCacheTimelineStore.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/LevelDBCacheTimelineStore.java index ccf2d94..86f4882 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/LevelDBCacheTimelineStore.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/LevelDBCacheTimelineStore.java @@ -19,6 +19,7 @@ package org.apache.hadoop.yarn.server.timeline; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.annotations.VisibleForTesting; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience.Private; @@ -65,16 +66,18 @@ private DB entityDb; private Configuration configuration; - public LevelDBCacheTimelineStore(String id, String name) { + public LevelDBCacheTimelineStore(String cacheId, String name) { super(name); - dbId = id; + dbId = cacheId + "_" + System.currentTimeMillis(); entityInsertTimes = new MemoryTimelineStore.HashMapStoreAdapter<>(); domainById = new MemoryTimelineStore.HashMapStoreAdapter<>(); domainsByOwner = new MemoryTimelineStore.HashMapStoreAdapter<>(); } - public LevelDBCacheTimelineStore(String id) { - this(id, LevelDBCacheTimelineStore.class.getName()); + @VisibleForTesting + @Private + LevelDBCacheTimelineStore(String cacheId) { + this(cacheId, LevelDBCacheTimelineStore.class.getName()); } @Override diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestLevelDBCacheTimelineStore.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestLevelDBCacheTimelineStore.java index 66da1e0..3e933d6 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestLevelDBCacheTimelineStore.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestLevelDBCacheTimelineStore.java @@ -27,9 +27,11 @@ public class TestLevelDBCacheTimelineStore extends TimelineStoreTestUtils { + static final String DEFAULT_CACHE_ID = "app1"; + @Before public void setup() throws Exception { - store = new LevelDBCacheTimelineStore("app1"); + store = new LevelDBCacheTimelineStore(DEFAULT_CACHE_ID); store.init(new YarnConfiguration()); store.start(); loadTestEntityData(); @@ -47,6 +49,15 @@ public TimelineStore getTimelineStore() { } @Test + public void testStoresWithSameCacheId() { + TimelineStore concurrentStore + = new LevelDBCacheTimelineStore(DEFAULT_CACHE_ID); + concurrentStore.init(new YarnConfiguration()); + concurrentStore.start(); + concurrentStore.stop(); + } + + @Test public void testGetSingleEntity() throws IOException { super.testGetSingleEntity(); }