Search in sources :

Example 1 with DBException

use of org.iq80.leveldb.DBException 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 2 with DBException

use of org.iq80.leveldb.DBException 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 3 with DBException

use of org.iq80.leveldb.DBException 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 4 with DBException

use of org.iq80.leveldb.DBException 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)

Example 5 with DBException

use of org.iq80.leveldb.DBException 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)

Aggregations

IOException (java.io.IOException)70 DBException (org.iq80.leveldb.DBException)70 JniDBFactory.asString (org.fusesource.leveldbjni.JniDBFactory.asString)39 LeveldbIterator (org.apache.hadoop.yarn.server.utils.LeveldbIterator)19 WriteBatch (org.iq80.leveldb.WriteBatch)18 Path (org.apache.hadoop.fs.Path)8 ByteString (com.google.protobuf.ByteString)6 File (java.io.File)6 Map (java.util.Map)6 NativeDB (org.fusesource.leveldbjni.internal.NativeDB)6 Options (org.iq80.leveldb.Options)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataOutputStream (java.io.DataOutputStream)5 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HashMap (java.util.HashMap)4 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)3 RawMessageTableEntry (co.cask.cdap.messaging.store.RawMessageTableEntry)3 TreeMap (java.util.TreeMap)3 ImmutableMessageTableEntry (co.cask.cdap.messaging.store.ImmutableMessageTableEntry)2