Search in sources :

Example 56 with DBException

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

the class LeveldbRMStateStore method dbStoreVersion.

void dbStoreVersion(Version state) throws IOException {
    String key = VERSION_NODE;
    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 57 with DBException

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

the class LeveldbRMStateStore method getNumEntriesInDatabase.

@VisibleForTesting
int getNumEntriesInDatabase() throws IOException {
    int numEntries = 0;
    LeveldbIterator iter = null;
    try {
        iter = new LeveldbIterator(db);
        iter.seekToFirst();
        while (iter.hasNext()) {
            Entry<byte[], byte[]> entry = iter.next();
            LOG.info("entry: " + asString(entry.getKey()));
            ++numEntries;
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        if (iter != null) {
            iter.close();
        }
    }
    return numEntries;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 58 with DBException

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

the class LeveldbRMStateStore method storeOrUpdateRMDT.

private void storeOrUpdateRMDT(RMDelegationTokenIdentifier tokenId, Long renewDate, boolean isUpdate) throws IOException {
    String tokenKey = getRMDTTokenNodeKey(tokenId);
    RMDelegationTokenIdentifierData tokenData = new RMDelegationTokenIdentifierData(tokenId, renewDate);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Storing token to " + tokenKey);
    }
    try {
        WriteBatch batch = db.createWriteBatch();
        try {
            batch.put(bytes(tokenKey), tokenData.toByteArray());
            if (!isUpdate) {
                ByteArrayOutputStream bs = new ByteArrayOutputStream();
                try (DataOutputStream ds = new DataOutputStream(bs)) {
                    ds.writeInt(tokenId.getSequenceNumber());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Storing " + tokenId.getSequenceNumber() + " to " + RM_DT_SEQUENCE_NUMBER_KEY);
                }
                batch.put(bytes(RM_DT_SEQUENCE_NUMBER_KEY), bs.toByteArray());
            }
            db.write(batch);
        } finally {
            batch.close();
        }
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) DataOutputStream(java.io.DataOutputStream) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) WriteBatch(org.iq80.leveldb.WriteBatch)

Example 59 with DBException

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

the class LeveldbRMStateStore method storeRMDTMasterKeyState.

@Override
protected void storeRMDTMasterKeyState(DelegationKey masterKey) throws IOException {
    String dbKey = getRMDTMasterKeyNodeKey(masterKey);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Storing token master key to " + dbKey);
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(os);
    try {
        masterKey.write(out);
    } finally {
        out.close();
    }
    try {
        db.put(bytes(dbKey), os.toByteArray());
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) DataOutputStream(java.io.DataOutputStream) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 60 with DBException

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

the class HistoryServerLeveldbStateStoreService method startStorage.

@Override
protected void startStorage() throws IOException {
    Path storeRoot = createStorageDir(getConfig());
    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;
        }
    }
    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) 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