Search in sources :

Example 1 with LeveldbIterator

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

the class TestLeveldbTimelineStore method deleteNextEntity.

private boolean deleteNextEntity(String entityType, byte[] ts) throws IOException, InterruptedException {
    LeveldbIterator iterator = null;
    LeveldbIterator pfIterator = null;
    try {
        iterator = ((LeveldbTimelineStore) store).getDbIterator(false);
        pfIterator = ((LeveldbTimelineStore) store).getDbIterator(false);
        return ((LeveldbTimelineStore) store).deleteNextEntity(entityType, ts, iterator, pfIterator, false);
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        IOUtils.cleanup(null, iterator, pfIterator);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) IOException(java.io.IOException)

Example 2 with LeveldbIterator

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

the class NMLeveldbStateStoreService method loadLocalizationState.

@Override
public RecoveredLocalizationState loadLocalizationState() throws IOException {
    RecoveredLocalizationState state = new RecoveredLocalizationState();
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(LOCALIZATION_PUBLIC_KEY_PREFIX));
        state.publicTrackerState = loadResourceTrackerState(iter, LOCALIZATION_PUBLIC_KEY_PREFIX);
        iter.seek(bytes(LOCALIZATION_PRIVATE_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.peekNext();
            String key = asString(entry.getKey());
            if (!key.startsWith(LOCALIZATION_PRIVATE_KEY_PREFIX)) {
                break;
            }
            int userEndPos = key.indexOf('/', LOCALIZATION_PRIVATE_KEY_PREFIX.length());
            if (userEndPos < 0) {
                throw new IOException("Unable to determine user in resource key: " + key);
            }
            String user = key.substring(LOCALIZATION_PRIVATE_KEY_PREFIX.length(), userEndPos);
            state.userResources.put(user, loadUserLocalizedResources(iter, key.substring(0, userEndPos + 1)));
        }
    } 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) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException)

Example 3 with LeveldbIterator

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

the class NMLeveldbStateStoreService method loadContainersState.

@Override
public List<RecoveredContainerState> loadContainersState() throws IOException {
    ArrayList<RecoveredContainerState> containers = new ArrayList<RecoveredContainerState>();
    ArrayList<ContainerId> containersToRemove = new ArrayList<ContainerId>();
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(CONTAINERS_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.peekNext();
            String key = asString(entry.getKey());
            if (!key.startsWith(CONTAINERS_KEY_PREFIX)) {
                break;
            }
            int idEndPos = key.indexOf('/', CONTAINERS_KEY_PREFIX.length());
            if (idEndPos < 0) {
                throw new IOException("Unable to determine container in key: " + key);
            }
            ContainerId containerId = ContainerId.fromString(key.substring(CONTAINERS_KEY_PREFIX.length(), idEndPos));
            String keyPrefix = key.substring(0, idEndPos + 1);
            RecoveredContainerState rcs = loadContainerState(containerId, iter, keyPrefix);
            // Don't load container without StartContainerRequest
            if (rcs.startRequest != null) {
                containers.add(rcs);
            } else {
                containersToRemove.add(containerId);
            }
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    // remove container without StartContainerRequest
    for (ContainerId containerId : containersToRemove) {
        LOG.warn("Remove container " + containerId + " with incomplete records");
        try {
            removeContainer(containerId);
        // TODO: kill and cleanup the leaked container
        } catch (IOException e) {
            LOG.error("Unable to remove container " + containerId + " in store", e);
        }
    }
    return containers;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ArrayList(java.util.ArrayList) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException)

Example 4 with LeveldbIterator

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

the class NMLeveldbStateStoreService method cleanupKeysWithPrefix.

private void cleanupKeysWithPrefix(String prefix) throws IOException {
    WriteBatch batch = null;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        try {
            batch = db.createWriteBatch();
            iter.seek(bytes(prefix));
            while (iter.hasNext()) {
                byte[] key = iter.next().getKey();
                String keyStr = asString(key);
                if (!keyStr.startsWith(prefix)) {
                    break;
                }
                batch.delete(key);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("cleanup " + keyStr + " from leveldb");
                }
            }
            db.write(batch);
        } catch (DBException e) {
            throw new IOException(e);
        } finally {
            if (batch != null) {
                batch.close();
            }
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
}
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) WriteBatch(org.iq80.leveldb.WriteBatch)

Example 5 with LeveldbIterator

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

the class NMLeveldbStateStoreService method loadDeletionServiceState.

@Override
public RecoveredDeletionServiceState loadDeletionServiceState() throws IOException {
    RecoveredDeletionServiceState state = new RecoveredDeletionServiceState();
    state.tasks = new ArrayList<DeletionServiceDeleteTaskProto>();
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(DELETION_TASK_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String key = asString(entry.getKey());
            if (!key.startsWith(DELETION_TASK_KEY_PREFIX)) {
                break;
            }
            state.tasks.add(DeletionServiceDeleteTaskProto.parseFrom(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) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) DeletionServiceDeleteTaskProto(org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.DeletionServiceDeleteTaskProto)

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