Search in sources :

Example 21 with LeveldbIterator

use of org.apache.hadoop.yarn.server.utils.LeveldbIterator in project hadoop by apache.

the class LeveldbTimelineStateStore method loadTokenMasterKeys.

private int loadTokenMasterKeys(TimelineServiceState state) throws IOException {
    byte[] base = KeyBuilder.newInstance().add(TOKEN_MASTER_KEY_ENTRY_PREFIX).getBytesForLookup();
    int numKeys = 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();
            loadTokenMasterKeyData(state, v);
            ++numKeys;
        }
    } finally {
        IOUtils.cleanup(LOG, iterator);
    }
    return numKeys;
}
Also used : LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator)

Example 22 with LeveldbIterator

use of org.apache.hadoop.yarn.server.utils.LeveldbIterator 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 23 with LeveldbIterator

use of org.apache.hadoop.yarn.server.utils.LeveldbIterator 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)

Example 24 with LeveldbIterator

use of org.apache.hadoop.yarn.server.utils.LeveldbIterator in project hadoop by apache.

the class LeveldbRMStateStore method getNumEntriesInDatabase.

@VisibleForTesting
int getNumEntriesInDatabase() throws IOException {
    int numEntries = 0;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seekToFirst();
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            LOG.info("entry: " + asString(entry.getKey()));
            ++numEntries;
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return numEntries;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 25 with LeveldbIterator

use of org.apache.hadoop.yarn.server.utils.LeveldbIterator in project hadoop by apache.

the class HistoryServerLeveldbStateStoreService method loadTokens.

private int loadTokens(HistoryServerState state) throws IOException {
    int numTokens = 0;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(TOKEN_STATE_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String key = asString(entry.getKey());
            if (!key.startsWith(TOKEN_STATE_KEY_PREFIX)) {
                break;
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Loading token from " + key);
            }
            try {
                loadToken(state, entry.getValue());
            } catch (IOException e) {
                throw new IOException("Error loading token state from " + key, e);
            }
            ++numTokens;
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return numTokens;
}
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

LeveldbIterator (org.apache.hadoop.yarn.server.utils.LeveldbIterator)26 IOException (java.io.IOException)25 DBException (org.iq80.leveldb.DBException)18 JniDBFactory.asString (org.fusesource.leveldbjni.JniDBFactory.asString)15 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 KeyParser (org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyParser)3 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 GenericObjectMapper.readReverseOrderedLong (org.apache.hadoop.yarn.server.timeline.GenericObjectMapper.readReverseOrderedLong)2 GenericObjectMapper.writeReverseOrderedLong (org.apache.hadoop.yarn.server.timeline.GenericObjectMapper.writeReverseOrderedLong)2 KeyBuilder (org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyBuilder)2 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Pattern (java.util.regex.Pattern)1 Path (org.apache.hadoop.fs.Path)1 DelegationKey (org.apache.hadoop.security.token.delegation.DelegationKey)1 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1