Search in sources :

Example 51 with DBException

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

the class NMLeveldbStateStoreService method removeApplication.

@Override
public void removeApplication(ApplicationId appId) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("removeApplication: appId=" + appId);
    }
    try {
        WriteBatch batch = db.createWriteBatch();
        try {
            String key = APPLICATIONS_KEY_PREFIX + appId;
            batch.delete(bytes(key));
            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 52 with DBException

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

the class LeveldbRMStateStore method removeApplication.

@Override
public synchronized void removeApplication(ApplicationId removeAppId) throws IOException {
    String appKey = getApplicationNodeKey(removeAppId);
    LOG.info("Removing state for app " + removeAppId);
    try {
        db.delete(bytes(appKey));
    } 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)

Example 53 with DBException

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

the class LeveldbRMStateStore method removeApplicationStateInternal.

@Override
protected void removeApplicationStateInternal(ApplicationStateData appState) throws IOException {
    ApplicationId appId = appState.getApplicationSubmissionContext().getApplicationId();
    String appKey = getApplicationNodeKey(appId);
    try {
        WriteBatch batch = db.createWriteBatch();
        try {
            batch.delete(bytes(appKey));
            for (ApplicationAttemptId attemptId : appState.attempts.keySet()) {
                String attemptKey = getApplicationAttemptNodeKey(appKey, attemptId);
                batch.delete(bytes(attemptKey));
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Removing state for app " + appId + " and " + appState.attempts.size() + " attempts" + " at " + appKey);
            }
            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) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) WriteBatch(org.iq80.leveldb.WriteBatch)

Example 54 with DBException

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

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

the class LeveldbRMStateStore method getAndIncrementEpoch.

@Override
public synchronized long getAndIncrementEpoch() throws Exception {
    long currentEpoch = 0;
    byte[] dbKeyBytes = bytes(EPOCH_NODE);
    try {
        byte[] data = db.get(dbKeyBytes);
        if (data != null) {
            currentEpoch = EpochProto.parseFrom(data).getEpoch();
        }
        EpochProto proto = Epoch.newInstance(currentEpoch + 1).getProto();
        db.put(dbKeyBytes, proto.toByteArray());
    } catch (DBException e) {
        throw new IOException(e);
    }
    return currentEpoch;
}
Also used : DBException(org.iq80.leveldb.DBException) EpochProto(org.apache.hadoop.yarn.proto.YarnServerResourceManagerRecoveryProtos.EpochProto) 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