org.fusesource.leveldbjni.JniDBFactory Java Examples
The following examples show how to use
org.fusesource.leveldbjni.JniDBFactory.
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: 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 #2
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 #3
Source File: LevelDBKeyValueStore.java From boon with Apache License 2.0 | 6 votes |
/** * Opens the database * * @param file filename to open * @param options options * @return */ private boolean openDB(File file, Options options) { try { database = JniDBFactory.factory.open(file, options); logger.info("Using JNI Level DB"); return true; } catch (IOException ex1) { try { database = Iq80DBFactory.factory.open(file, options); logger.info("Using Java Level DB"); return false; } catch (IOException ex2) { return Exceptions.handle(Boolean.class, ex2); } } }
Example #4
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 #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: 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 #7
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 #8
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 #9
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 #10
Source File: HistoryServerLeveldbStateStoreService.java From hadoop 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 #11
Source File: LeveldbFailStore.java From light-task-scheduler with Apache License 2.0 | 5 votes |
public void destroy() throws FailStoreException { try { close(); JniDBFactory.factory.destroy(dbPath, options); } catch (IOException e) { throw new FailStoreException(e); } finally { if (fileLock != null) { fileLock.release(); } FileUtils.delete(dbPath); } }
Example #12
Source File: LeveldbFailStore.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public void open() throws FailStoreException { try { JniDBFactory.factory.repair(dbPath, options); db = JniDBFactory.factory.open(dbPath, options); } catch (IOException e) { throw new FailStoreException(e); } }
Example #13
Source File: WarpInit.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(true); options.verifyChecksums(true); options.paranoidChecks(true); DB db = null; boolean nativedisabled = "true".equals(System.getProperty(Configuration.LEVELDB_NATIVE_DISABLE)); boolean javadisabled = "true".equals(System.getProperty(Configuration.LEVELDB_JAVA_DISABLE)); try { if (!nativedisabled) { db = JniDBFactory.factory.open(new File(path), options); } else { throw new UnsatisfiedLinkError("Native LevelDB implementation disabled."); } } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); if (!javadisabled) { db = Iq80DBFactory.factory.open(new File(path), options); } else { throw new RuntimeException("No usable LevelDB implementation, aborting."); } } db.close(); }
Example #14
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 #15
Source File: LevelDBStorage.java From greycat with Apache License 2.0 | 5 votes |
@Override public void connect(Graph graph, Callback<Boolean> callback) { if (isConnected) { if (callback != null) { callback.on(null); } return; } this.graph = graph; //by default activate snappy compression of bytes Options options = new Options() .createIfMissing(true) .compressionType(CompressionType.SNAPPY); File location = new File(storagePath); if (!location.exists()) { location.mkdirs(); } File targetDB = new File(location, "data"); targetDB.mkdirs(); try { if (useNative) { db = JniDBFactory.factory.open(targetDB, options); } else { db = Iq80DBFactory.factory.open(targetDB, options); } isConnected = true; if (callback != null) { callback.on(true); } } catch (Exception e) { e.printStackTrace(); if (callback != null) { callback.on(null); } } }
Example #16
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 #17
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 #18
Source File: NMLeveldbStateStoreService.java From hadoop 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 #19
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 #20
Source File: PBImageTextWriter.java From hadoop 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 #21
Source File: WarpCompact.java From warp10-platform with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws IOException { if (args.length != 3) { System.err.println("Usage: WarpCompact /path/to/leveldb/dir STARTKEY(hex) ENDKEY(hex)"); System.exit(-1); } String path = args[0]; Options options = new Options(); if (null != System.getProperty(Configuration.LEVELDB_BLOCK_SIZE)) { options.blockSize(Integer.parseInt(System.getProperty(Configuration.LEVELDB_BLOCK_SIZE))); } DB db = null; boolean nativedisabled = "true".equals(System.getProperty(Configuration.LEVELDB_NATIVE_DISABLE)); boolean javadisabled = "true".equals(System.getProperty(Configuration.LEVELDB_JAVA_DISABLE)); try { if (!nativedisabled) { db = JniDBFactory.factory.open(new File(path), options); } else { throw new UnsatisfiedLinkError("Native LevelDB implementation disabled."); } } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); if (!javadisabled) { db = Iq80DBFactory.factory.open(new File(path), options); } else { throw new RuntimeException("No usable LevelDB implementation, aborting."); } } final DB fdb = db; Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { fdb.close(); } catch (Exception e) { e.printStackTrace(); } } }); byte[] begin = null; byte[] end = null; if (!"".equals(args[1])) { begin = Hex.decode(args[1]); } if (!"".equals(args[2])) { end = Hex.decode(args[2]); } db.compactRange(begin, end); }
Example #22
Source File: LeveldbTimelineStore.java From big-c with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") protected void serviceInit(Configuration conf) throws Exception { Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_TTL_MS, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_TTL_MS) > 0, "%s property value should be greater than zero", YarnConfiguration.TIMELINE_SERVICE_TTL_MS); Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS) > 0, "%s property value should be greater than zero", YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS); Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE) >= 0, "%s property value should be greater than or equal to zero", YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE); Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE) > 0, " %s property value should be greater than zero", YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE); Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE) > 0, "%s property value should be greater than zero", YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE); Options options = new Options(); options.createIfMissing(true); options.cacheSize(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE)); JniDBFactory factory = new JniDBFactory(); Path dbPath = new Path( conf.get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_PATH), FILENAME); 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, LEVELDB_DIR_UMASK); } } finally { IOUtils.cleanup(LOG, localFS); } LOG.info("Using leveldb path " + dbPath); db = factory.open(new File(dbPath.toString()), options); checkVersion(); startTimeWriteCache = Collections.synchronizedMap(new LRUMap(getStartTimeWriteCacheSize( conf))); startTimeReadCache = Collections.synchronizedMap(new LRUMap(getStartTimeReadCacheSize( conf))); if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_TTL_ENABLE, true)) { deletionThread = new EntityDeletionThread(conf); deletionThread.start(); } super.serviceInit(conf); }
Example #23
Source File: LeveldbTimelineStore.java From hadoop with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") protected void serviceInit(Configuration conf) throws Exception { Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_TTL_MS, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_TTL_MS) > 0, "%s property value should be greater than zero", YarnConfiguration.TIMELINE_SERVICE_TTL_MS); Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS) > 0, "%s property value should be greater than zero", YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS); Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE) >= 0, "%s property value should be greater than or equal to zero", YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE); Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE) > 0, " %s property value should be greater than zero", YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE); Preconditions.checkArgument(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE) > 0, "%s property value should be greater than zero", YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE); Options options = new Options(); options.createIfMissing(true); options.cacheSize(conf.getLong( YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE)); JniDBFactory factory = new JniDBFactory(); Path dbPath = new Path( conf.get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_PATH), FILENAME); 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, LEVELDB_DIR_UMASK); } } finally { IOUtils.cleanup(LOG, localFS); } LOG.info("Using leveldb path " + dbPath); db = factory.open(new File(dbPath.toString()), options); checkVersion(); startTimeWriteCache = Collections.synchronizedMap(new LRUMap(getStartTimeWriteCacheSize( conf))); startTimeReadCache = Collections.synchronizedMap(new LRUMap(getStartTimeReadCacheSize( conf))); if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_TTL_ENABLE, true)) { deletionThread = new EntityDeletionThread(conf); deletionThread.start(); } super.serviceInit(conf); }
Example #24
Source File: EzLevelDbJniFactory.java From ezdb with Apache License 2.0 | 4 votes |
@Override public DB open(File path, Options options) throws IOException { return JniDBFactory.factory.open(path, options); }
Example #25
Source File: EzLevelDbJniFactory.java From ezdb with Apache License 2.0 | 4 votes |
@Override public void destroy(File path, Options options) throws IOException { JniDBFactory.factory.destroy(path, options); }
Example #26
Source File: LevelDBStore.java From hadoop-ozone with Apache License 2.0 | 4 votes |
@Override public void destroy() throws IOException { close(); JniDBFactory.factory.destroy(dbFile, dbOptions); }