use of org.iq80.leveldb.DB in project hadoop by apache.
the class LeveldbTimelineStateStore method loadTokens.
private int loadTokens(TimelineServiceState state) throws IOException {
byte[] base = KeyBuilder.newInstance().add(TOKEN_ENTRY_PREFIX).getBytesForLookup();
int numTokens = 0;
LeveldbIterator iterator = null;
try {
for (iterator = new LeveldbIterator(db), iterator.seek(base); iterator.hasNext(); iterator.next()) {
byte[] k = iterator.peekNext().getKey();
if (!prefixMatches(base, base.length, k)) {
break;
}
byte[] v = iterator.peekNext().getValue();
loadTokenData(state, v);
++numTokens;
}
} catch (DBException e) {
throw new IOException(e);
} finally {
IOUtils.cleanup(LOG, iterator);
}
return numTokens;
}
use of org.iq80.leveldb.DB in project hadoop by apache.
the class TestRollingLevelDB method testInsertForPreviousPeriodAfterRollPeriodRollsDB.
@Test
public void testInsertForPreviousPeriodAfterRollPeriodRollsDB() throws Exception {
rollingLevelDB.init(conf);
long now = rollingLevelDB.currentTimeMillis();
now = rollingLevelDB.computeCurrentCheckMillis(now);
rollingLevelDB.setCurrentTimeMillis(now);
DB db = rollingLevelDB.getDBForStartTime(now - 1);
long startTime = rollingLevelDB.getStartTimeFor(db);
Assert.assertEquals("Received level db for incorrect start time", rollingLevelDB.computeCurrentCheckMillis(now - 1), startTime);
}
use of org.iq80.leveldb.DB in project hadoop by apache.
the class NMLeveldbStateStoreService method loadApplicationsState.
@Override
public RecoveredApplicationsState loadApplicationsState() throws IOException {
RecoveredApplicationsState state = new RecoveredApplicationsState();
state.applications = new ArrayList<ContainerManagerApplicationProto>();
String keyPrefix = APPLICATIONS_KEY_PREFIX;
LeveldbIterator iter = null;
try {
iter = new LeveldbIterator(db);
iter.seek(bytes(keyPrefix));
while (iter.hasNext()) {
Entry<byte[], byte[]> entry = iter.next();
String key = asString(entry.getKey());
if (!key.startsWith(keyPrefix)) {
break;
}
state.applications.add(ContainerManagerApplicationProto.parseFrom(entry.getValue()));
}
} catch (DBException e) {
throw new IOException(e);
} finally {
if (iter != null) {
iter.close();
}
}
cleanupDeprecatedFinishedApps();
return state;
}
use of org.iq80.leveldb.DB in project hadoop by apache.
the class TestNMLeveldbStateStoreService method testCompactionCycle.
@Test
public void testCompactionCycle() throws IOException {
final DB mockdb = mock(DB.class);
conf.setInt(YarnConfiguration.NM_RECOVERY_COMPACTION_INTERVAL_SECS, 1);
NMLeveldbStateStoreService store = new NMLeveldbStateStoreService() {
@Override
protected void checkVersion() {
}
@Override
protected DB openDatabase(Configuration conf) {
return mockdb;
}
};
store.init(conf);
store.start();
verify(mockdb, timeout(10000)).compactRange((byte[]) isNull(), (byte[]) isNull());
store.close();
}
use of org.iq80.leveldb.DB in project hadoop by apache.
the class LeveldbRMStateStore method loadRMApps.
private void loadRMApps(RMState state) throws IOException {
int numApps = 0;
int numAppAttempts = 0;
LeveldbIterator iter = null;
try {
iter = new LeveldbIterator(db);
iter.seek(bytes(RM_APP_KEY_PREFIX));
while (iter.hasNext()) {
Entry<byte[], byte[]> entry = iter.next();
String key = asString(entry.getKey());
if (!key.startsWith(RM_APP_KEY_PREFIX)) {
break;
}
String appIdStr = key.substring(RM_APP_ROOT.length() + 1);
if (appIdStr.contains(SEPARATOR)) {
LOG.warn("Skipping extraneous data " + key);
continue;
}
numAppAttempts += loadRMApp(state, iter, appIdStr, entry.getValue());
++numApps;
}
} catch (DBException e) {
throw new IOException(e);
} finally {
if (iter != null) {
iter.close();
}
}
LOG.info("Recovered " + numApps + " applications and " + numAppAttempts + " application attempts");
}
Aggregations