Search in sources :

Example 11 with DBException

use of org.iq80.leveldb.DBException in project hadoop by apache.

the class NMLeveldbStateStoreService method storeContainer.

@Override
public void storeContainer(ContainerId containerId, int containerVersion, StartContainerRequest startRequest) throws IOException {
    String idStr = containerId.toString();
    if (LOG.isDebugEnabled()) {
        LOG.debug("storeContainer: containerId= " + idStr + ", startRequest= " + startRequest);
    }
    String keyRequest = CONTAINERS_KEY_PREFIX + idStr + CONTAINER_REQUEST_KEY_SUFFIX;
    String keyVersion = getContainerVersionKey(idStr);
    try {
        WriteBatch batch = db.createWriteBatch();
        try {
            batch.put(bytes(keyRequest), ((StartContainerRequestPBImpl) startRequest).getProto().toByteArray());
            if (containerVersion != 0) {
                batch.put(bytes(keyVersion), bytes(Integer.toString(containerVersion)));
            }
            db.write(batch);
        } finally {
            batch.close();
        }
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) StartContainerRequestPBImpl(org.apache.hadoop.yarn.api.protocolrecords.impl.pb.StartContainerRequestPBImpl) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) WriteBatch(org.iq80.leveldb.WriteBatch)

Example 12 with DBException

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

use of org.iq80.leveldb.DBException in project hadoop by apache.

the class NMLeveldbStateStoreService method removeLocalizedResource.

@Override
public void removeLocalizedResource(String user, ApplicationId appId, Path localPath) throws IOException {
    String localPathStr = localPath.toString();
    String startedKey = getResourceStartedKey(user, appId, localPathStr);
    String completedKey = getResourceCompletedKey(user, appId, localPathStr);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Removing local resource at " + localPathStr);
    }
    try {
        WriteBatch batch = db.createWriteBatch();
        try {
            batch.delete(bytes(startedKey));
            batch.delete(bytes(completedKey));
            db.write(batch);
        } finally {
            batch.close();
        }
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) WriteBatch(org.iq80.leveldb.WriteBatch)

Example 14 with DBException

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

use of org.iq80.leveldb.DBException in project hadoop by apache.

the class LeveldbRMStateStore method loadRMAppAttemptState.

@VisibleForTesting
ApplicationAttemptStateData loadRMAppAttemptState(ApplicationAttemptId attemptId) throws IOException {
    String attemptKey = getApplicationAttemptNodeKey(attemptId);
    byte[] data = null;
    try {
        data = db.get(bytes(attemptKey));
    } catch (DBException e) {
        throw new IOException(e);
    }
    if (data == null) {
        return null;
    }
    return createAttemptState(attemptId.toString(), data);
}
Also used : DBException(org.iq80.leveldb.DBException) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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