Search in sources :

Example 21 with Options

use of org.iq80.leveldb.Options in project cdap by caskdata.

the class LevelDBTableService method openTable.

private DB openTable(String tableName) throws IOException {
    String dbPath = getDBPath(basePath, tableName);
    Options options = new Options();
    options.createIfMissing(false);
    options.errorIfExists(false);
    options.comparator(new KeyValueDBComparator());
    options.blockSize(blockSize);
    options.cacheSize(cacheSize);
    // unfortunately, with the java version of leveldb, with createIfMissing set to false, factory.open will
    // see that there is no table and throw an exception, but it wont clean up after itself and will leave a
    // directory there with a lock.  So we want to avoid calling open if the path doesn't already exist and
    // throw the exception ourselves.
    File dbDir = new File(dbPath);
    if (!dbDir.exists()) {
        throw new IOException("Database " + dbPath + " does not exist and the create if missing option is disabled");
    }
    DB db = factory.open(dbDir, options);
    tables.put(tableName, db);
    return db;
}
Also used : WriteOptions(org.iq80.leveldb.WriteOptions) Options(org.iq80.leveldb.Options) IOException(java.io.IOException) File(java.io.File) DB(org.iq80.leveldb.DB)

Example 22 with Options

use of org.iq80.leveldb.Options in project cdap by caskdata.

the class LevelDBTableService method dropTable.

public void dropTable(String name) throws IOException {
    DB db = tables.remove(name);
    if (db != null) {
        db.close();
    }
    String dbPath = getDBPath(basePath, name);
    factory.destroy(new File(dbPath), new Options());
}
Also used : WriteOptions(org.iq80.leveldb.WriteOptions) Options(org.iq80.leveldb.Options) File(java.io.File) DB(org.iq80.leveldb.DB)

Example 23 with Options

use of org.iq80.leveldb.Options in project java-tron by tronprotocol.

the class LevelDbDataSourceImpl method initDB.

@Override
public void initDB() {
    resetDbLock.writeLock().lock();
    try {
        logger.debug("~> LevelDbDataSourceImpl.initDB(): " + dataBaseName);
        if (isAlive()) {
            return;
        }
        if (dataBaseName == null) {
            throw new NullPointerException("no name set to the dbStore");
        }
        Options dbOptions = createDbOptions();
        try {
            openDatabase(dbOptions);
            alive = true;
        } catch (IOException ioe) {
            throw new RuntimeException("Can't initialize database", ioe);
        }
    } finally {
        resetDbLock.writeLock().unlock();
    }
}
Also used : Options(org.iq80.leveldb.Options) IOException(java.io.IOException)

Example 24 with Options

use of org.iq80.leveldb.Options in project Mycat_plus by coderczp.

the class LevelDBCachePooFactory method createCachePool.

@Override
public CachePool createCachePool(String poolName, int cacheSize, int expireSeconds) {
    Options options = new Options();
    // cacheSize M 大小
    options.cacheSize(cacheSize * 1048576);
    options.createIfMissing(true);
    DB db = null;
    try {
        db = factory.open(new File("leveldb\\" + poolName), options);
    // Use the db in here....
    } catch (Exception e) {
    // Make sure you close the db to shutdown the
    // database and avoid resource leaks.
    // db.close();
    }
    return new LevelDBPool(poolName, db, cacheSize);
}
Also used : Options(org.iq80.leveldb.Options) File(java.io.File) DB(org.iq80.leveldb.DB)

Example 25 with Options

use of org.iq80.leveldb.Options in project dble by actiontech.

the class LevelDBCachePooFactory method createCachePool.

@Override
public CachePool createCachePool(String poolName, int cacheSize, int expireSeconds) {
    Options options = new Options();
    // cacheSize M
    options.cacheSize(1048576L * cacheSize);
    options.createIfMissing(true);
    DB db = null;
    String filePath = "leveldb\\" + poolName;
    try {
        db = factory.open(new File(filePath), options);
    // Use the db in here....
    } catch (IOException e) {
        LOGGER.info("factory try to open file " + filePath + " failed ");
    // Make sure you close the db to shutdown the
    // database and avoid resource leaks.
    // db.close();
    }
    return new LevelDBPool(poolName, db, cacheSize);
}
Also used : Options(org.iq80.leveldb.Options) IOException(java.io.IOException) File(java.io.File) DB(org.iq80.leveldb.DB)

Aggregations

Options (org.iq80.leveldb.Options)26 File (java.io.File)21 IOException (java.io.IOException)14 DB (org.iq80.leveldb.DB)10 Path (org.apache.hadoop.fs.Path)8 NativeDB (org.fusesource.leveldbjni.internal.NativeDB)6 DBException (org.iq80.leveldb.DBException)6 WriteOptions (org.iq80.leveldb.WriteOptions)5 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 AtomicReference (java.util.concurrent.atomic.AtomicReference)1