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;
}
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());
}
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();
}
}
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);
}
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);
}
Aggregations