Search in sources :

Example 6 with LeveldbIterator

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

the class NMLeveldbStateStoreService method loadContainerTokensState.

@Override
public RecoveredContainerTokensState loadContainerTokensState() throws IOException {
    RecoveredContainerTokensState state = new RecoveredContainerTokensState();
    state.activeTokens = new HashMap<ContainerId, Long>();
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(CONTAINER_TOKENS_KEY_PREFIX));
        final int containerTokensKeyPrefixLength = CONTAINER_TOKENS_KEY_PREFIX.length();
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String fullKey = asString(entry.getKey());
            if (!fullKey.startsWith(CONTAINER_TOKENS_KEY_PREFIX)) {
                break;
            }
            String key = fullKey.substring(containerTokensKeyPrefixLength);
            if (key.equals(CURRENT_MASTER_KEY_SUFFIX)) {
                state.currentMasterKey = parseMasterKey(entry.getValue());
            } else if (key.equals(PREV_MASTER_KEY_SUFFIX)) {
                state.previousMasterKey = parseMasterKey(entry.getValue());
            } else if (key.startsWith(ConverterUtils.CONTAINER_PREFIX)) {
                loadContainerToken(state, fullKey, key, entry.getValue());
            }
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return state;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException)

Example 7 with LeveldbIterator

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

the class NMLeveldbStateStoreService method loadNMTokensState.

@Override
public RecoveredNMTokensState loadNMTokensState() throws IOException {
    RecoveredNMTokensState state = new RecoveredNMTokensState();
    state.applicationMasterKeys = new HashMap<ApplicationAttemptId, MasterKey>();
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(NM_TOKENS_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String fullKey = asString(entry.getKey());
            if (!fullKey.startsWith(NM_TOKENS_KEY_PREFIX)) {
                break;
            }
            String key = fullKey.substring(NM_TOKENS_KEY_PREFIX.length());
            if (key.equals(CURRENT_MASTER_KEY_SUFFIX)) {
                state.currentMasterKey = parseMasterKey(entry.getValue());
            } else if (key.equals(PREV_MASTER_KEY_SUFFIX)) {
                state.previousMasterKey = parseMasterKey(entry.getValue());
            } else if (key.startsWith(ApplicationAttemptId.appAttemptIdStrPrefix)) {
                ApplicationAttemptId attempt;
                try {
                    attempt = ApplicationAttemptId.fromString(key);
                } catch (IllegalArgumentException e) {
                    throw new IOException("Bad application master key state for " + fullKey, e);
                }
                state.applicationMasterKeys.put(attempt, parseMasterKey(entry.getValue()));
            }
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return state;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) MasterKey(org.apache.hadoop.yarn.server.api.records.MasterKey) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException)

Example 8 with LeveldbIterator

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

the class NMLeveldbStateStoreService method loadLogDeleterState.

@Override
public RecoveredLogDeleterState loadLogDeleterState() throws IOException {
    RecoveredLogDeleterState state = new RecoveredLogDeleterState();
    state.logDeleterMap = new HashMap<ApplicationId, LogDeleterProto>();
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(LOG_DELETER_KEY_PREFIX));
        final int logDeleterKeyPrefixLength = LOG_DELETER_KEY_PREFIX.length();
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String fullKey = asString(entry.getKey());
            if (!fullKey.startsWith(LOG_DELETER_KEY_PREFIX)) {
                break;
            }
            String appIdStr = fullKey.substring(logDeleterKeyPrefixLength);
            ApplicationId appId = null;
            try {
                appId = ApplicationId.fromString(appIdStr);
            } catch (IllegalArgumentException e) {
                LOG.warn("Skipping unknown log deleter key " + fullKey);
                continue;
            }
            LogDeleterProto proto = LogDeleterProto.parseFrom(entry.getValue());
            state.logDeleterMap.put(appId, proto);
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return state;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) LogDeleterProto(org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.LogDeleterProto) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId)

Example 9 with LeveldbIterator

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

the class LeveldbRMStateStore method loadRMDTSecretManagerTokens.

private int loadRMDTSecretManagerTokens(RMState state) throws IOException {
    int numTokens = 0;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(RM_DT_TOKEN_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String key = asString(entry.getKey());
            if (!key.startsWith(RM_DT_TOKEN_KEY_PREFIX)) {
                break;
            }
            RMDelegationTokenIdentifierData tokenData = loadDelegationToken(entry.getValue());
            RMDelegationTokenIdentifier tokenId = tokenData.getTokenIdentifier();
            long renewDate = tokenData.getRenewDate();
            state.rmSecretManagerState.delegationTokenState.put(tokenId, renewDate);
            ++numTokens;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Loaded RM delegation token from " + key + ": tokenId=" + tokenId + ", renewDate=" + renewDate);
            }
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return numTokens;
}
Also used : DBException(org.iq80.leveldb.DBException) RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) RMDelegationTokenIdentifier(org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier) IOException(java.io.IOException)

Example 10 with LeveldbIterator

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

the class LeveldbRMStateStore method loadRMDTSecretManagerKeys.

private int loadRMDTSecretManagerKeys(RMState state) throws IOException {
    int numKeys = 0;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(RM_DT_MASTER_KEY_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String key = asString(entry.getKey());
            if (!key.startsWith(RM_DT_MASTER_KEY_KEY_PREFIX)) {
                break;
            }
            DelegationKey masterKey = loadDelegationKey(entry.getValue());
            state.rmSecretManagerState.masterKeyState.add(masterKey);
            ++numKeys;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Loaded RM delegation key from " + key + ": keyId=" + masterKey.getKeyId() + ", expirationDate=" + masterKey.getExpiryDate());
            }
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return numKeys;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) DelegationKey(org.apache.hadoop.security.token.delegation.DelegationKey) 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