|
@@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server.timeline;
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
import com.google.common.base.Preconditions;
|
|
|
import org.apache.commons.collections.map.LRUMap;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
@@ -33,6 +34,7 @@ import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.io.WritableComparator;
|
|
|
import org.apache.hadoop.service.AbstractService;
|
|
|
+import org.apache.hadoop.util.Time;
|
|
|
import org.apache.hadoop.yarn.api.records.timeline.*;
|
|
|
import org.apache.hadoop.yarn.api.records.timeline.TimelineEvents.EventsOfOneEntity;
|
|
|
import org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse.TimelinePutError;
|
|
@@ -123,6 +125,11 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
@VisibleForTesting
|
|
|
static final String FILENAME = "leveldb-timeline-store.ldb";
|
|
|
|
|
|
+ @VisibleForTesting
|
|
|
+ //Extension to FILENAME where backup will be stored in case we need to
|
|
|
+ //call LevelDb recovery
|
|
|
+ static final String BACKUP_EXT = ".backup-";
|
|
|
+
|
|
|
private static final byte[] START_TIME_LOOKUP_PREFIX = "k".getBytes(Charset.forName("UTF-8"));
|
|
|
private static final byte[] ENTITY_ENTRY_PREFIX = "e".getBytes(Charset.forName("UTF-8"));
|
|
|
private static final byte[] INDEXED_ENTRY_PREFIX = "i".getBytes(Charset.forName("UTF-8"));
|
|
@@ -175,6 +182,13 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
super(LeveldbTimelineStore.class.getName());
|
|
|
}
|
|
|
|
|
|
+ private JniDBFactory factory;
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ void setFactory(JniDBFactory fact) {
|
|
|
+ this.factory = fact;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@SuppressWarnings("unchecked")
|
|
|
protected void serviceInit(Configuration conf) throws Exception {
|
|
@@ -209,7 +223,10 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
options.cacheSize(conf.getLong(
|
|
|
YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE,
|
|
|
YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE));
|
|
|
- JniDBFactory factory = new JniDBFactory();
|
|
|
+ if(factory == null) {
|
|
|
+ factory = new JniDBFactory();
|
|
|
+ }
|
|
|
+
|
|
|
Path dbPath = new Path(
|
|
|
conf.get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_PATH), FILENAME);
|
|
|
FileSystem localFS = null;
|
|
@@ -226,7 +243,19 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
IOUtils.cleanup(LOG, localFS);
|
|
|
}
|
|
|
LOG.info("Using leveldb path " + dbPath);
|
|
|
- db = factory.open(new File(dbPath.toString()), options);
|
|
|
+ try {
|
|
|
+ db = factory.open(new File(dbPath.toString()), options);
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ File dbFile = new File(dbPath.toString());
|
|
|
+ File backupPath = new File(
|
|
|
+ dbPath.toString() + BACKUP_EXT + Time.monotonicNow());
|
|
|
+ LOG.warn("Incurred exception while loading LevelDb database. Backing " +
|
|
|
+ "up at "+ backupPath, ioe);
|
|
|
+ FileUtils.copyDirectory(dbFile, backupPath);
|
|
|
+ LOG.warn("Going to try repair");
|
|
|
+ factory.repair(dbFile, options);
|
|
|
+ db = factory.open(dbFile, options);
|
|
|
+ }
|
|
|
checkVersion();
|
|
|
startTimeWriteCache =
|
|
|
Collections.synchronizedMap(new LRUMap(getStartTimeWriteCacheSize(
|