Search in sources :

Example 36 with DB

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;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) IOException(java.io.IOException)

Example 37 with DB

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);
}
Also used : DB(org.iq80.leveldb.DB) Test(org.junit.Test)

Example 38 with DB

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;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) ContainerManagerApplicationProto(org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.ContainerManagerApplicationProto)

Example 39 with DB

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();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) DB(org.iq80.leveldb.DB) Test(org.junit.Test)

Example 40 with DB

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");
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)25 DB (org.iq80.leveldb.DB)25 DBException (org.iq80.leveldb.DBException)20 LeveldbIterator (org.apache.hadoop.yarn.server.utils.LeveldbIterator)16 Options (org.iq80.leveldb.Options)16 File (java.io.File)15 JniDBFactory.asString (org.fusesource.leveldbjni.JniDBFactory.asString)14 WriteBatch (org.iq80.leveldb.WriteBatch)9 DBIterator (org.iq80.leveldb.DBIterator)7 Map (java.util.Map)5 Path (org.apache.hadoop.fs.Path)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 NavigableMap (java.util.NavigableMap)4 NativeDB (org.fusesource.leveldbjni.internal.NativeDB)4 WriteOptions (org.iq80.leveldb.WriteOptions)4 DB (com.codecademy.eventhub.base.DB)3 Provides (com.google.inject.Provides)3 ArrayList (java.util.ArrayList)3