Search in sources :

Example 41 with DB

use of org.iq80.leveldb.DB 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 42 with DB

use of org.iq80.leveldb.DB in project EventHub by Codecademy.

the class UserStorageModule method getIdMap.

@Provides
public IdMap getIdMap(@Named("eventhub.userstorage.directory") String userStorageDirectory) throws IOException {
    String filename = userStorageDirectory + "/id_map.db";
    //noinspection ResultOfMethodCallIgnored
    new File(userStorageDirectory).mkdirs();
    Options options = new Options();
    options.createIfMissing(true);
    return IdMap.create(new DB(JniDBFactory.factory.open(new File(filename), options)));
}
Also used : Options(org.iq80.leveldb.Options) File(java.io.File) DB(com.codecademy.eventhub.base.DB) Provides(com.google.inject.Provides)

Example 43 with DB

use of org.iq80.leveldb.DB in project EventHub by Codecademy.

the class PropertiesIndexModule method getPropertiesIndex.

@Provides
public PropertiesIndex getPropertiesIndex(@Named("eventhub.directory") String eventIndexDirectory) throws IOException {
    //noinspection ResultOfMethodCallIgnored
    new File(eventIndexDirectory).mkdirs();
    Options options = new Options();
    options.createIfMissing(true);
    return new PropertiesIndex(new DB(JniDBFactory.factory.open(new File(eventIndexDirectory + "/properties_index.db"), options)));
}
Also used : Options(org.iq80.leveldb.Options) File(java.io.File) DB(com.codecademy.eventhub.base.DB) Provides(com.google.inject.Provides)

Example 44 with DB

use of org.iq80.leveldb.DB 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)

Example 45 with DB

use of org.iq80.leveldb.DB 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)

Aggregations

IOException (java.io.IOException)25 DB (org.iq80.leveldb.DB)25 DBException (org.iq80.leveldb.DBException)20 LeveldbIterator (org.apache.hadoop.yarn.server.utils.LeveldbIterator)16 Options (org.iq80.leveldb.Options)16 File (java.io.File)15 JniDBFactory.asString (org.fusesource.leveldbjni.JniDBFactory.asString)14 WriteBatch (org.iq80.leveldb.WriteBatch)9 DBIterator (org.iq80.leveldb.DBIterator)7 Map (java.util.Map)5 Path (org.apache.hadoop.fs.Path)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 NavigableMap (java.util.NavigableMap)4 NativeDB (org.fusesource.leveldbjni.internal.NativeDB)4 WriteOptions (org.iq80.leveldb.WriteOptions)4 DB (com.codecademy.eventhub.base.DB)3 Provides (com.google.inject.Provides)3 ArrayList (java.util.ArrayList)3