Search in sources :

Example 21 with DBException

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

the class LeveldbRMStateStore method openDatabase.

protected DB openDatabase() throws Exception {
    Path storeRoot = createStorageDir();
    Options options = new Options();
    options.createIfMissing(false);
    options.logger(new LeveldbLogger());
    LOG.info("Using state database at " + storeRoot + " for recovery");
    File dbfile = new File(storeRoot.toString());
    try {
        db = JniDBFactory.factory.open(dbfile, options);
    } catch (NativeDB.DBException e) {
        if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
            LOG.info("Creating state database at " + dbfile);
            options.createIfMissing(true);
            try {
                db = JniDBFactory.factory.open(dbfile, options);
                // store version
                storeVersion();
            } catch (DBException dbErr) {
                throw new IOException(dbErr.getMessage(), dbErr);
            }
        } else {
            throw e;
        }
    }
    return db;
}
Also used : Path(org.apache.hadoop.fs.Path) Options(org.iq80.leveldb.Options) DBException(org.iq80.leveldb.DBException) IOException(java.io.IOException) NativeDB(org.fusesource.leveldbjni.internal.NativeDB) File(java.io.File)

Example 22 with DBException

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

the class LeveldbRMStateStore method loadReservationState.

private void loadReservationState(RMState rmState) throws IOException {
    int numReservations = 0;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seek(bytes(RM_RESERVATION_KEY_PREFIX));
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            String key = asString(entry.getKey());
            String planReservationString = key.substring(RM_RESERVATION_KEY_PREFIX.length());
            String[] parts = planReservationString.split(SEPARATOR);
            if (parts.length != 2) {
                LOG.warn("Incorrect reservation state key " + key);
                continue;
            }
            String planName = parts[0];
            String reservationName = parts[1];
            ReservationAllocationStateProto allocationState = ReservationAllocationStateProto.parseFrom(entry.getValue());
            if (!rmState.getReservationState().containsKey(planName)) {
                rmState.getReservationState().put(planName, new HashMap<ReservationId, ReservationAllocationStateProto>());
            }
            ReservationId reservationId = ReservationId.parseReservationId(reservationName);
            rmState.getReservationState().get(planName).put(reservationId, allocationState);
            numReservations++;
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    LOG.info("Recovered " + numReservations + " reservations");
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) ReservationAllocationStateProto(org.apache.hadoop.yarn.proto.YarnProtos.ReservationAllocationStateProto)

Example 23 with DBException

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

Example 24 with DBException

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

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

the class ShuffleHandler method startStore.

private void startStore(Path recoveryRoot) throws IOException {
    Options options = new Options();
    options.createIfMissing(false);
    options.logger(new LevelDBLogger());
    Path dbPath = new Path(recoveryRoot, STATE_DB_NAME);
    LOG.info("Using state database at " + dbPath + " for recovery");
    File dbfile = new File(dbPath.toString());
    try {
        stateDb = JniDBFactory.factory.open(dbfile, options);
    } catch (NativeDB.DBException e) {
        if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
            LOG.info("Creating state database at " + dbfile);
            options.createIfMissing(true);
            try {
                stateDb = JniDBFactory.factory.open(dbfile, options);
                storeVersion();
            } catch (DBException dbExc) {
                throw new IOException("Unable to create state store", dbExc);
            }
        } else {
            throw e;
        }
    }
    checkVersion();
}
Also used : Path(org.apache.hadoop.fs.Path) Options(org.iq80.leveldb.Options) DBException(org.iq80.leveldb.DBException) IOException(java.io.IOException) NativeDB(org.fusesource.leveldbjni.internal.NativeDB) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

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