org.iq80.leveldb.Options Java Examples
The following examples show how to use
org.iq80.leveldb.Options.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LevelDBCachePooFactory.java From dble with GNU General Public License v2.0 | 6 votes |
@Override public CachePool createCachePool(String poolName, int cacheSize, int expireSeconds) { Options options = new Options(); options.cacheSize(1048576L * cacheSize); //cacheSize M 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); }
Example #2
Source File: LevelDbDataSourceImpl.java From gsc-core with GNU Lesser General Public License v3.0 | 6 votes |
private void openDatabase(Options dbOptions) throws IOException { final Path dbPath = getDbPath(); if (!Files.isSymbolicLink(dbPath.getParent())) { Files.createDirectories(dbPath.getParent()); } try { database = factory.open(dbPath.toFile(), dbOptions); } catch (IOException e) { if (e.getMessage().contains("Corruption:")) { factory.repair(dbPath.toFile(), dbOptions); database = factory.open(dbPath.toFile(), dbOptions); } else { throw e; } } }
Example #3
Source File: LevelDB.java From aion with MIT License | 6 votes |
private void repair() { if (isOpen()) { this.close(); } File f = new File(path); Options options = setupLevelDbOptions(); try { LOG.warn("attempting to repair database {}", this.toString()); // attempt repair JniDBFactory.factory.repair(f, options); } catch (Exception e2) { LOG.error("Failed to repair the database " + this.toString() + " due to: ", e2); } this.open(); }
Example #4
Source File: LevelDB.java From aion with MIT License | 6 votes |
private Options setupLevelDbOptions() { Options options = new Options(); options.createIfMissing(true); options.compressionType( enableDbCompression ? CompressionType.SNAPPY : CompressionType.NONE); options.blockSize(this.blockSize); options.writeBufferSize(this.writeBufferSize); // (levelDb default: 8mb) options.cacheSize(enableDbCache ? this.cacheSize : 0); options.paranoidChecks(true); options.verifyChecksums(true); options.maxOpenFiles(this.maxOpenFiles); LOG.info("LevelDb Options: EnableCompression:{} MaxOpenFiles:{} BlockSize:{} WriteBuffer:{} EnableCache:{} CacheSize:{}" , enableDbCompression, maxOpenFiles, blockSize, writeBufferSize, enableDbCache, cacheSize); return options; }
Example #5
Source File: LevelDBStore.java From hadoop-ozone with Apache License 2.0 | 6 votes |
private void openDB(File dbPath, Options options) throws IOException { if (dbPath.getParentFile().mkdirs()) { if (LOG.isDebugEnabled()) { LOG.debug("Db path {} created.", dbPath.getParentFile()); } } db = JniDBFactory.factory.open(dbPath, options); if (LOG.isDebugEnabled()) { LOG.debug("LevelDB successfully opened"); LOG.debug("[Option] cacheSize = {}", options.cacheSize()); LOG.debug("[Option] createIfMissing = {}", options.createIfMissing()); LOG.debug("[Option] blockSize = {}", options.blockSize()); LOG.debug("[Option] compressionType= {}", options.compressionType()); LOG.debug("[Option] maxOpenFiles= {}", options.maxOpenFiles()); LOG.debug("[Option] writeBufferSize= {}", options.writeBufferSize()); } }
Example #6
Source File: EzLevelDbTable.java From ezdb with Apache License 2.0 | 6 votes |
public EzLevelDbTable(File path, EzLevelDbFactory factory, Serde<H> hashKeySerde, Serde<R> rangeKeySerde, Serde<V> valueSerde, Comparator<byte[]> hashKeyComparator, Comparator<byte[]> rangeKeyComparator) { this.hashKeySerde = hashKeySerde; this.rangeKeySerde = rangeKeySerde; this.valueSerde = valueSerde; this.hashKeyComparator = hashKeyComparator; this.rangeKeyComparator = rangeKeyComparator; Options options = new Options(); options.createIfMissing(true); options.comparator(new EzLevelDbComparator(hashKeyComparator, rangeKeyComparator)); try { this.db = factory.open(path, options); } catch (IOException e) { throw new DbException(e); } }
Example #7
Source File: SelectLevelDBData.java From gsc-core with GNU Lesser General Public License v3.0 | 6 votes |
public static void data(String dataName) { Options options = new Options(); //options.createIfMissing(true); DB db = null; try { System.out.println("Path: " + path + dataName); db = factory.open(new File(path + dataName), options); logger.info("---------------------------------------------"); System.out.println(); DBIterator iterator = db.iterator(); iterator.seekToFirst(); int count = 0; while (iterator.hasNext()) { count++; switch (dataName) { case "properties": properties(iterator.peekNext().getKey(), iterator.peekNext().getValue()); break; case "peers": peers(iterator.peekNext().getKey(), iterator.peekNext().getValue()); break; case "nodes": peers(iterator.peekNext().getKey(), iterator.peekNext().getValue()); break; default: break; } iterator.next(); } iterator.close(); System.out.println(dataName + " Num: " + count); System.out.println(); logger.info("---------------------------------------------"); db.close(); } catch (IOException e) { e.printStackTrace(); } }
Example #8
Source File: LevelDB.java From SPADE with GNU General Public License v3.0 | 6 votes |
public boolean initialize(String arguments) { try { WriteOptions writeOptions = new WriteOptions(); writeOptions.sync(false); directoryPath = arguments; Options options = new Options(); options.createIfMissing(true); options.compressionType(CompressionType.NONE); // scaffoldDatabase = factory.open(new File(directoryPath), options); childDatabase = factory.open(new File(directoryPath + "child"), options); parentDatabase = factory.open(new File(directoryPath + "parent"), options); logger.log(Level.INFO, "Scaffold initialized"); // globalTxCheckin(true); } catch(IOException ex) { logger.log(Level.SEVERE, null, ex); return false; } return true; }
Example #9
Source File: LevelDBManager.java From nuls with MIT License | 6 votes |
/** * 装载数据库 * 如果Area自定义了比较器,保存area的自定义比较器,下次启动数据库时获取并装载它 * 如果Area自定义了cacheSize,保存area的自定义cacheSize,下次启动数据库时获取并装载它,否则,启动已存在的Area时会丢失之前的cacheSize设置。 * load database * If the area custom comparator, save area define the comparator, the next time you start the database access and loaded it * If the area custom cacheSize, save the area's custom cacheSize, get and load it the next time you start the database, or you'll lose the cacheSize setting before starting the existing area. */ private static DB openDB(String dbPath, boolean createIfMissing, Long cacheSize, Comparator<byte[]> comparator) throws IOException { File file = new File(dbPath); String areaName = getAreaNameFromDbPath(dbPath); Options options = new Options().createIfMissing(createIfMissing); if (cacheSize != null) { putModel(BASE_AREA_NAME, bytes(areaName + "-cacheSize"), cacheSize); options.cacheSize(cacheSize); } if (comparator != null) { putModel(BASE_AREA_NAME, bytes(areaName + "-comparator"), comparator); AREAS_COMPARATOR.put(areaName, comparator); } DBFactory factory = Iq80DBFactory.factory; return factory.open(file, options); }
Example #10
Source File: WarpRepair.java From warp10-platform with Apache License 2.0 | 6 votes |
public static void repair(String path, Options options, boolean javadisabled, boolean nativedisabled) throws IOException { try { if (!nativedisabled) { JniDBFactory.factory.repair(new File(path), options); } else { throw new UnsatisfiedLinkError("Native LevelDB implementation disabled."); } } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); if (!javadisabled) { LevelDBRepair.repair(new File(path), options); } else { throw new RuntimeException("No usable LevelDB implementation, aborting."); } } }
Example #11
Source File: WarpDB.java From warp10-platform with Apache License 2.0 | 6 votes |
public Options getOptions() { // // Clone the current options // Options opt = new Options(); opt.blockRestartInterval(options.blockRestartInterval()); opt.blockSize(options.blockSize()); opt.cacheSize(options.cacheSize()); opt.comparator(options.comparator()); opt.compressionType(options.compressionType()); opt.createIfMissing(options.createIfMissing()); opt.errorIfExists(options.errorIfExists()); opt.logger(options.logger()); opt.maxOpenFiles(options.maxOpenFiles()); opt.paranoidChecks(options.paranoidChecks()); opt.verifyChecksums(options.verifyChecksums()); opt.writeBufferSize(options.writeBufferSize()); return opt; }
Example #12
Source File: ShuffleHandler.java From big-c with Apache License 2.0 | 6 votes |
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(); }
Example #13
Source File: LeveldbRMStateStore.java From hadoop with Apache License 2.0 | 6 votes |
@Override protected void startInternal() 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; } } }
Example #14
Source File: ShuffleHandler.java From hadoop with Apache License 2.0 | 6 votes |
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(); }
Example #15
Source File: LeveldbRMStateStore.java From big-c with Apache License 2.0 | 6 votes |
@Override protected void startInternal() 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; } } }
Example #16
Source File: ShuffleHandler.java From tez with Apache License 2.0 | 6 votes |
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(); }
Example #17
Source File: JLevelDBState.java From jesos with Apache License 2.0 | 5 votes |
public JLevelDBState(final String path) throws IOException { checkNotNull(path, "path is null"); final Options options = new Options(); options.createIfMissing(true); this.db = Iq80DBFactory.factory.open(new File(path), options); }
Example #18
Source File: TrackDatabaseTest.java From ethereumj with MIT License | 5 votes |
@AfterClass public static void destroyDB() { try { Options options = new Options(); factory.destroy(new File("temp"), options); } catch (IOException e) { fail("Destroying temp-db failed"); } }
Example #19
Source File: WarpDB.java From warp10-platform with Apache License 2.0 | 5 votes |
private synchronized void open(boolean nativedisabled, boolean javadisabled, String home, Options options) throws IOException { try { mutex.lockInterruptibly(); // Wait for iterators and other ops to finish while(pendingOps.get() > 0 || compactionsSuspended.get()) { LockSupport.parkNanos(100000000L); } if (null != db) { this.db.close(); this.db = null; } try { if (!nativedisabled) { db = JniDBFactory.factory.open(new File(home), options); } else { throw new UnsatisfiedLinkError("Native LevelDB implementation disabled."); } } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); if (!javadisabled) { System.out.println("WARNING: falling back to pure java implementation of LevelDB."); db = Iq80DBFactory.factory.open(new File(home), options); } else { throw new RuntimeException("No usable LevelDB implementation, aborting."); } } } catch (InterruptedException ie) { throw new RuntimeException("Interrupted while opending LevelDB.", ie); } finally { if (mutex.isHeldByCurrentThread()) { mutex.unlock(); } } }
Example #20
Source File: LevelDBHandle.java From SPADE with GNU General Public License v3.0 | 5 votes |
@Override public void clear() throws Exception{ db.close(); factory.destroy(new File(dbPath), new Options()); Options options = new Options().createIfMissing(true); db = factory.open(new File(dbPath), options); }
Example #21
Source File: MCAFile2LevelDB.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public MCAFile2LevelDB(File folderFrom, File folderTo) { super(folderFrom, folderTo); this.startTime = System.currentTimeMillis(); try { if (!folderTo.exists()) { folderTo.mkdirs(); } String worldName = folderTo.getName(); try (PrintStream out = new PrintStream(new FileOutputStream(new File(folderTo, "levelname.txt")))) { out.print(worldName); } this.pool = new ForkJoinPool(); this.remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PC, ClipboardRemapper.RemapPlatform.PE); BundledBlockData.getInstance().loadFromResource(); int bufferSize = (int) Math.min(Integer.MAX_VALUE, Math.max((long) (MemUtil.getFreeBytes() * 0.8), 134217728)); this.db = Iq80DBFactory.factory.open(new File(folderTo, "db"), new Options() .createIfMissing(true) .verifyChecksums(false) .compressionType(CompressionType.ZLIB) .blockSize(262144) // 256K .cacheSize(8388608) // 8MB .writeBufferSize(134217728) // >=512MB ); // try { // this.db.suspendCompactions(); // } catch (InterruptedException e) { // e.printStackTrace(); // } } catch (IOException e) { throw new RuntimeException(e); } }
Example #22
Source File: DatabaseImpl.java From ethereumj with MIT License | 5 votes |
public DatabaseImpl(String name) { // Initialize Database this.name = name; Options options = new Options(); options.createIfMissing(true); options.compressionType(CompressionType.NONE); try { logger.debug("Opening database"); File dbLocation = new File(System.getProperty("user.dir") + "/" + SystemProperties.CONFIG.databaseDir() + "/"); File fileLocation = new File(dbLocation, name); if(SystemProperties.CONFIG.databaseReset()) { destroyDB(fileLocation); } logger.debug("Initializing new or existing database: '{}'", name); db = factory.open(fileLocation, options); // logger.debug("Showing database stats"); // String stats = DATABASE.getProperty("leveldb.stats"); // logger.debug(stats); if (logger.isTraceEnabled()){ logger.trace("Dump for: {}", fileLocation.toString()); DBIterator iter = db.iterator(); while(iter.hasNext()){ byte[] key = iter.peekNext().getKey(); byte[] value = iter.peekNext().getValue(); logger.trace("key={}, value={}", Hex.toHexString(key), Hex.toHexString(value)); iter.next(); } } } catch (IOException ioe) { logger.error(ioe.getMessage(), ioe); throw new RuntimeException("Can't initialize database"); } }
Example #23
Source File: MCAFile2LevelDB.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public synchronized void compact() { // Since the library doesn't support it, only way to flush the cache is to loop over everything try (DB newDb = Iq80DBFactory.factory.open(new File(folderTo, "db"), new Options() .verifyChecksums(false) .blockSize(262144) // 256K .cacheSize(8388608) // 8MB .writeBufferSize(134217728) // >=128MB )) { newDb.close(); } catch (Throwable ignore) {} Fawe.debug("Done compacting!"); }
Example #24
Source File: DatabaseImpl.java From ethereumj with MIT License | 5 votes |
public void destroyDB(File fileLocation) { logger.debug("Destroying existing database"); Options options = new Options(); try { factory.destroy(fileLocation, options); } catch (IOException e) { logger.error(e.getMessage(), e); } }
Example #25
Source File: EzLevelDb.java From ezdb with Apache License 2.0 | 5 votes |
@Override public void deleteTable(String tableName) { try { synchronized (cache) { cache.remove(tableName); factory.destroy(getFile(tableName), new Options()); } } catch (IOException e) { throw new DbException(e); } }
Example #26
Source File: WarpRepair.java From warp10-platform with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { String path = args[0]; Options options = new Options(); options.createIfMissing(false); options.maxOpenFiles(200); options.verifyChecksums(!("true".equals(System.getProperty(DISABLE_CHECKSUMS)))); options.paranoidChecks(!("true".equals(System.getProperty(DISABLE_PARANOIDCHECKS)))); boolean nativedisabled = "true".equals(System.getProperty(Configuration.LEVELDB_NATIVE_DISABLE)); boolean javadisabled = "true".equals(System.getProperty(Configuration.LEVELDB_JAVA_DISABLE)); repair(path, options, javadisabled, nativedisabled); }
Example #27
Source File: PBImageTextWriter.java From big-c with Apache License 2.0 | 5 votes |
LevelDBStore(final File dbPath) throws IOException { Options options = new Options(); options.createIfMissing(true); options.errorIfExists(true); db = JniDBFactory.factory.open(dbPath, options); batch = db.createWriteBatch(); }
Example #28
Source File: NMLeveldbStateStoreService.java From big-c with Apache License 2.0 | 5 votes |
@Override protected void initStorage(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; } } checkVersion(); }
Example #29
Source File: HistoryServerLeveldbStateStoreService.java From big-c with Apache License 2.0 | 5 votes |
@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(); }
Example #30
Source File: WarpDB.java From warp10-platform with Apache License 2.0 | 5 votes |
public WarpDB(boolean nativedisabled, boolean javadisabled, String home, Options options) throws IOException { this.nativedisabled = nativedisabled; this.javadisabled = javadisabled; this.options = options; this.home = home; this.setName("[WarpDB Command Thread]"); this.setDaemon(true); this.start(); this.open(nativedisabled, javadisabled, home, options); }