Search in sources :

Example 1 with Options

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

the class LevelDBCacheTimelineStore method serviceInit.

@Override
protected synchronized void serviceInit(Configuration conf) throws Exception {
    configuration = conf;
    Options options = new Options();
    options.createIfMissing(true);
    options.cacheSize(conf.getLong(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_CACHE_READ_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_CACHE_READ_CACHE_SIZE));
    JniDBFactory factory = new JniDBFactory();
    Path dbPath = new Path(conf.get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_PATH), dbId + CACHED_LDB_FILE_PREFIX);
    FileSystem localFS = null;
    try {
        localFS = FileSystem.getLocal(conf);
        if (!localFS.exists(dbPath)) {
            if (!localFS.mkdirs(dbPath)) {
                throw new IOException("Couldn't create directory for leveldb " + "timeline store " + dbPath);
            }
            localFS.setPermission(dbPath, LeveldbUtils.LEVELDB_DIR_UMASK);
        }
    } finally {
        IOUtils.cleanup(LOG, localFS);
    }
    LOG.info("Using leveldb path " + dbPath);
    entityDb = factory.open(new File(dbPath.toString()), options);
    entities = new LevelDBMapAdapter<>(entityDb);
    super.serviceInit(conf);
}
Also used : Path(org.apache.hadoop.fs.Path) Options(org.iq80.leveldb.Options) FileSystem(org.apache.hadoop.fs.FileSystem) JniDBFactory(org.fusesource.leveldbjni.JniDBFactory) IOException(java.io.IOException) File(java.io.File)

Example 2 with Options

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

the class NMLeveldbStateStoreService method openDatabase.

protected DB openDatabase(Configuration conf) throws IOException {
    Path storeRoot = createStorageDir(conf);
    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);
            isNewlyCreated = true;
            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 3 with Options

use of org.iq80.leveldb.Options 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 4 with Options

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

Example 5 with Options

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

the class LeveldbTimelineStateStore method startStorage.

@Override
protected void startStorage() throws IOException {
    Options options = new Options();
    Path dbPath = new Path(getConfig().get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_STATE_STORE_PATH), DB_NAME);
    FileSystem localFS = null;
    try {
        localFS = FileSystem.getLocal(getConfig());
        if (!localFS.exists(dbPath)) {
            if (!localFS.mkdirs(dbPath)) {
                throw new IOException("Couldn't create directory for leveldb " + "timeline store " + dbPath);
            }
            localFS.setPermission(dbPath, LEVELDB_DIR_UMASK);
        }
    } finally {
        IOUtils.cleanup(LOG, localFS);
    }
    JniDBFactory factory = new JniDBFactory();
    try {
        options.createIfMissing(false);
        db = factory.open(new File(dbPath.toString()), options);
        LOG.info("Loading the existing database at th path: " + dbPath.toString());
        checkVersion();
    } catch (NativeDB.DBException e) {
        if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
            try {
                options.createIfMissing(true);
                db = factory.open(new File(dbPath.toString()), options);
                LOG.info("Creating a new database at th path: " + dbPath.toString());
                storeVersion(CURRENT_VERSION_INFO);
            } catch (DBException ex) {
                throw new IOException(ex);
            }
        } else {
            throw new IOException(e);
        }
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Options(org.iq80.leveldb.Options) DBException(org.iq80.leveldb.DBException) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) JniDBFactory(org.fusesource.leveldbjni.JniDBFactory) NativeDB(org.fusesource.leveldbjni.internal.NativeDB) File(java.io.File)

Aggregations

Options (org.iq80.leveldb.Options)29 File (java.io.File)23 IOException (java.io.IOException)16 DB (org.iq80.leveldb.DB)10 Path (org.apache.hadoop.fs.Path)8 DBException (org.iq80.leveldb.DBException)8 NativeDB (org.fusesource.leveldbjni.internal.NativeDB)6 WriteOptions (org.iq80.leveldb.WriteOptions)5 ReadOptions (org.iq80.leveldb.ReadOptions)4 DB (com.codecademy.eventhub.base.DB)3 Provides (com.google.inject.Provides)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 JniDBFactory (org.fusesource.leveldbjni.JniDBFactory)3 RandomAccessFile (java.io.RandomAccessFile)2 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)1 FileInputStream (java.io.FileInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 URI (java.net.URI)1 Map (java.util.Map)1