Search in sources :

Example 41 with DBException

use of org.iq80.leveldb.DBException in project tez 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 42 with DBException

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

the class ShuffleHandler method recordJobShuffleInfo.

private void recordJobShuffleInfo(JobID jobId, String user, Token<JobTokenIdentifier> jobToken) throws IOException {
    if (stateDb != null) {
        TokenProto tokenProto = TokenProto.newBuilder().setIdentifier(ByteString.copyFrom(jobToken.getIdentifier())).setPassword(ByteString.copyFrom(jobToken.getPassword())).setKind(jobToken.getKind().toString()).setService(jobToken.getService().toString()).build();
        JobShuffleInfoProto proto = JobShuffleInfoProto.newBuilder().setUser(user).setJobToken(tokenProto).build();
        try {
            stateDb.put(bytes(jobId.toString()), proto.toByteArray());
        } catch (DBException e) {
            throw new IOException("Error storing " + jobId, e);
        }
    }
    addJobToken(jobId, user, jobToken);
}
Also used : DBException(org.iq80.leveldb.DBException) JobShuffleInfoProto(org.apache.hadoop.mapred.proto.ShuffleHandlerRecoveryProtos.JobShuffleInfoProto) TokenProto(org.apache.hadoop.security.proto.SecurityProtos.TokenProto) IOException(java.io.IOException)

Example 43 with DBException

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

the class RollingLevelDBTimelineStore method dbStoreVersion.

private void dbStoreVersion(Version state) throws IOException {
    String key = TIMELINE_STORE_VERSION_KEY;
    byte[] data = ((VersionPBImpl) state).getProto().toByteArray();
    try {
        starttimedb.put(bytes(key), data);
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) IOException(java.io.IOException)

Example 44 with DBException

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

the class LeveldbTimelineStateStore method loadTokens.

private int loadTokens(TimelineServiceState state) throws IOException {
    byte[] base = KeyBuilder.newInstance().add(TOKEN_ENTRY_PREFIX).getBytesForLookup();
    int numTokens = 0;
    LeveldbIterator iterator = null;
    try {
        for (iterator = new LeveldbIterator(db), iterator.seek(base); iterator.hasNext(); iterator.next()) {
            byte[] k = iterator.peekNext().getKey();
            if (!prefixMatches(base, base.length, k)) {
                break;
            }
            byte[] v = iterator.peekNext().getValue();
            loadTokenData(state, v);
            ++numTokens;
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        IOUtils.cleanup(LOG, iterator);
    }
    return numTokens;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) IOException(java.io.IOException)

Example 45 with DBException

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

the class LeveldbTimelineStateStore method loadVersion.

@VisibleForTesting
Version loadVersion() throws IOException {
    try {
        byte[] data = db.get(TIMELINE_STATE_STORE_VERSION_KEY);
        // if version is not stored previously, treat it as CURRENT_VERSION_INFO.
        if (data == null || data.length == 0) {
            return getCurrentVersion();
        }
        Version version = new VersionPBImpl(YarnServerCommonProtos.VersionProto.parseFrom(data));
        return version;
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) VersionPBImpl(org.apache.hadoop.yarn.server.records.impl.pb.VersionPBImpl) Version(org.apache.hadoop.yarn.server.records.Version) 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