From f71ccb3e64768ad12f3728f709082ae58cc36686 Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Tue, 20 Nov 2018 20:04:50 -0800 Subject: [PATCH 2/2] YARN-9027 --- .../yarn/server/timeline/LevelDBCacheTimelineStore.java | 8 ++++++++ .../server/timeline/TestLevelDBCacheTimelineStore.java | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/LevelDBCacheTimelineStore.java b/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 f7a3d01..9912e51 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/LevelDBCacheTimelineStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/LevelDBCacheTimelineStore.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; /** * LevelDB implementation of {@link KeyValueBasedTimelineStore}. This @@ -64,6 +65,8 @@ private String dbId; private DB entityDb; private Configuration configuration; + private static final AtomicInteger dbCtr = new AtomicInteger(0); + private static final String CACHED_LDB_FILENAME = "db"; public LevelDBCacheTimelineStore(String id, String name) { super(name); @@ -77,6 +80,11 @@ public LevelDBCacheTimelineStore(String id) { this(id, LevelDBCacheTimelineStore.class.getName()); } + public LevelDBCacheTimelineStore() { + this(CACHED_LDB_FILENAME + String.valueOf(dbCtr.getAndIncrement()), + LevelDBCacheTimelineStore.class.getName()); + } + @Override protected synchronized void serviceInit(Configuration conf) throws Exception { configuration = conf; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestLevelDBCacheTimelineStore.java b/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..89583b2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestLevelDBCacheTimelineStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestLevelDBCacheTimelineStore.java @@ -19,12 +19,15 @@ package org.apache.hadoop.yarn.server.timeline; import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.util.ReflectionUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.io.IOException; +import static org.junit.Assert.assertNotNull; + public class TestLevelDBCacheTimelineStore extends TimelineStoreTestUtils { @Before @@ -47,6 +50,18 @@ public TimelineStore getTimelineStore() { } @Test + public void testDefaultConstructor() { + TimelineStore store = null; + try { + store = ReflectionUtils.newInstance(LevelDBCacheTimelineStore.class, + new YarnConfiguration()); + } finally { + assertNotNull(store); + } + } + + + @Test public void testGetSingleEntity() throws IOException { super.testGetSingleEntity(); } -- 2.7.4 (Apple Git-66)