Search in sources :

Example 61 with DBException

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

the class HistoryServerLeveldbStateStoreService method dbStoreVersion.

void dbStoreVersion(Version state) throws IOException {
    String key = DB_SCHEMA_VERSION_KEY;
    byte[] data = ((VersionPBImpl) state).getProto().toByteArray();
    try {
        db.put(bytes(key), data);
    } 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 62 with DBException

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

the class HistoryServerLeveldbStateStoreService method storeTokenMasterKey.

@Override
public void storeTokenMasterKey(DelegationKey masterKey) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Storing master key " + masterKey.getKeyId());
    }
    ByteArrayOutputStream memStream = new ByteArrayOutputStream();
    DataOutputStream dataStream = new DataOutputStream(memStream);
    try {
        masterKey.write(dataStream);
        dataStream.close();
        dataStream = null;
    } finally {
        IOUtils.cleanup(LOG, dataStream);
    }
    String dbKey = getTokenMasterKeyDatabaseKey(masterKey);
    try {
        db.put(bytes(dbKey), memStream.toByteArray());
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException)

Example 63 with DBException

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

the class HistoryServerLeveldbStateStoreService method loadTokens.

private int loadTokens(HistoryServerState state) throws IOException {
    int numTokens = 0;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(TOKEN_STATE_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String key = asString(entry.getKey());
            if (!key.startsWith(TOKEN_STATE_KEY_PREFIX)) {
                break;
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Loading token from " + key);
            }
            try {
                loadToken(state, entry.getValue());
            } catch (IOException e) {
                throw new IOException("Error loading token state from " + key, e);
            }
            ++numTokens;
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return numTokens;
}
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 64 with DBException

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

the class ShuffleHandler method recoverState.

private void recoverState(Configuration conf) throws IOException {
    Path recoveryRoot = getRecoveryPath();
    if (recoveryRoot != null) {
        startStore(recoveryRoot);
        Pattern jobPattern = Pattern.compile(JobID.JOBID_REGEX);
        LeveldbIterator iter = null;
        try {
            iter = new LeveldbIterator(stateDb);
            iter.seek(bytes(JobID.JOB));
            while (iter.hasNext()) {
                Map.Entry<byte[], byte[]> entry = iter.next();
                String key = asString(entry.getKey());
                if (!jobPattern.matcher(key).matches()) {
                    break;
                }
                recoverJobShuffleInfo(key, entry.getValue());
            }
        } catch (DBException e) {
            throw new IOException("Database error during recovery", e);
        } finally {
            if (iter != null) {
                iter.close();
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Pattern(java.util.regex.Pattern) DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 65 with DBException

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

the class ShuffleHandler method storeSchemaVersion.

private void storeSchemaVersion(Version version) throws IOException {
    String key = STATE_DB_SCHEMA_VERSION_KEY;
    byte[] data = ((VersionPBImpl) version).getProto().toByteArray();
    try {
        stateDb.put(bytes(key), data);
    } catch (DBException e) {
        throw new IOException(e.getMessage(), e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ByteString(com.google.protobuf.ByteString) 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