org.iq80.leveldb.WriteOptions Java Examples
The following examples show how to use
org.iq80.leveldb.WriteOptions.
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: WarpDB.java From warp10-platform with Apache License 2.0 | 6 votes |
@Override public Snapshot delete(byte[] key, WriteOptions options) throws DBException { if (options.snapshot()) { throw new RuntimeException("Snapshots are unsupported."); } try { mutex.lockInterruptibly(); pendingOps.incrementAndGet(); } catch (InterruptedException ie) { throw new DBException("Interrupted while acquiring DB mutex.", ie); } finally { if (mutex.isHeldByCurrentThread()) { mutex.unlock(); } } try { return this.db.delete(key, options); } finally { this.pendingOps.decrementAndGet(); } }
Example #2
Source File: WarpDB.java From warp10-platform with Apache License 2.0 | 6 votes |
@Override public Snapshot put(byte[] key, byte[] value, WriteOptions options) throws DBException { if (options.snapshot()) { throw new RuntimeException("Snapshots are unsupported."); } try { mutex.lockInterruptibly(); pendingOps.incrementAndGet(); } catch (InterruptedException ie) { throw new DBException("Interrupted while acquiring DB mutex.", ie); } finally { if (mutex.isHeldByCurrentThread()) { mutex.unlock(); } } try { return this.db.put(key, value, options); } finally { this.pendingOps.decrementAndGet(); } }
Example #3
Source File: WarpDB.java From warp10-platform with Apache License 2.0 | 6 votes |
@Override public Snapshot write(WriteBatch updates, WriteOptions options) throws DBException { if (options.snapshot()) { throw new RuntimeException("Snapshots are unsupported."); } try { mutex.lockInterruptibly(); pendingOps.incrementAndGet(); } catch (InterruptedException ie) { throw new DBException("Interrupted while acquiring DB mutex.", ie); } finally { if (mutex.isHeldByCurrentThread()) { mutex.unlock(); } } try { return this.db.write(updates, options); } finally { this.pendingOps.decrementAndGet(); } }
Example #4
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 #5
Source File: LevelDBStore.java From hadoop-ozone with Apache License 2.0 | 5 votes |
public LevelDBStore(File dbPath, boolean createIfMissing) throws IOException { dbOptions = new Options(); dbOptions.createIfMissing(createIfMissing); this.dbFile = dbPath; this.writeOptions = new WriteOptions().sync(true); openDB(dbPath, dbOptions); }
Example #6
Source File: LevelDBStore.java From hadoop-ozone with Apache License 2.0 | 5 votes |
/** * Opens a DB file. * * @param dbPath - DB File path * @throws IOException */ public LevelDBStore(File dbPath, Options options) throws IOException { dbOptions = options; this.dbFile = dbPath; this.writeOptions = new WriteOptions().sync(true); openDB(dbPath, dbOptions); }
Example #7
Source File: LevelDbDataSourceImpl.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
private void updateByBatchInner(Map<byte[], byte[]> rows, WriteOptions options) throws Exception { try (WriteBatch batch = database.createWriteBatch()) { rows.forEach((key, value) -> { if (value == null) { batch.delete(key); } else { batch.put(key, value); } }); database.write(batch, options); } }
Example #8
Source File: LevelDbUtil.java From mcg-helper with Apache License 2.0 | 5 votes |
public synchronized static <T> void putObject(String key, T t) throws IOException { if(key != null && !"".equals(key)) { WriteOptions writeOptions = new WriteOptions().sync(true);//write后立即进行磁盘同步写,且线程安全 db.put(key.getBytes(Constants.CHARSET), JSON.toJSONBytes(t), writeOptions); } }
Example #9
Source File: StandaloneDirectoryClient.java From warp10-platform with Apache License 2.0 | 5 votes |
private void store(byte[] key, byte[] value) throws IOException { if (null == this.db) { return; } WriteBatch batch = perThreadWriteBatch.get(); AtomicLong size = perThreadWriteBatchSize.get(); boolean written = false; WriteOptions options = new WriteOptions().sync(null == key || null == value || 1.0 == syncrate); try { if (null != key && null != value) { batch.put(key, value); size.addAndGet(key.length + value.length); } if (null == key || null == value || size.get() > MAX_BATCH_SIZE) { if (syncwrites && !options.sync()) { options = new WriteOptions().sync(Math.random() < syncrate); } this.db.write(batch, options); size.set(0L); perThreadWriteBatch.remove(); written = true; } } finally { if (written) { batch.close(); } } }
Example #10
Source File: StandaloneStoreClient.java From warp10-platform with Apache License 2.0 | 5 votes |
private void store(List<byte[][]> kvs) throws IOException { //WriteBatch batch = this.db.createWriteBatch(); WriteBatch batch = perThreadWriteBatch.get(); AtomicLong size = perThreadWriteBatchSize.get(); boolean written = false; try { if (null != kvs) { for (byte[][] kv: kvs) { batch.put(kv[0], kv[1]); size.addAndGet(kv[0].length + kv[1].length); } } if (null == kvs || size.get() > MAX_ENCODER_SIZE) { WriteOptions options = new WriteOptions().sync(null == kvs || 1.0 == syncrate); if (syncwrites && !options.sync()) { options = new WriteOptions().sync(Math.random() < syncrate); } this.db.write(batch, options); size.set(0L); perThreadWriteBatch.remove(); written = true; } //this.db.write(batch); } finally { if (written) { batch.close(); } } }
Example #11
Source File: JLevelDBState.java From jesos with Apache License 2.0 | 5 votes |
@Override public Future<Variable> store(final Variable variable) { checkNotNull(variable, "variable is null"); checkState(!closed.get(), "already closed"); checkState(variable instanceof JVariable, "can not process native variable, use JVariable"); final JVariable v = (JVariable) variable; return executor.submit(new Callable<Variable>() { @Override public Variable call() throws Exception { final WriteOptions writeOptions = new WriteOptions(); writeOptions.sync(true); final String internedName = v.getName().intern(); synchronized (internedName) { final JVariable current = load(internedName); if (current == null || current.getUuid().equals(v.getUuid())) { final JVariable update = new JVariable(internedName, v.value()); final WriteBatch writeBatch = db.createWriteBatch(); writeBatch.delete(bytes(internedName)); writeBatch.put(bytes(internedName), update.getEntry().toByteArray()); db.write(writeBatch, writeOptions); return update; } else { return null; } } } }); }
Example #12
Source File: JLevelDBState.java From jesos with Apache License 2.0 | 5 votes |
@Override public Future<Boolean> expunge(final Variable variable) { checkNotNull(variable, "variable is null"); checkState(!closed.get(), "already closed"); checkState(variable instanceof JVariable, "can not process native variable, use JVariable"); final JVariable v = (JVariable) variable; return executor.submit(new Callable<Boolean>() { @Override public Boolean call() throws Exception { final WriteOptions writeOptions = new WriteOptions(); writeOptions.sync(true); final String internedName = v.getName().intern(); synchronized (internedName) { final JVariable current = load(internedName); if (current != null && current.getUuid().equals(v.getUuid())) { db.delete(bytes(internedName)); return Boolean.TRUE; } else { return Boolean.FALSE; } } } }); }
Example #13
Source File: StandaloneStoreClient.java From warp10-platform with Apache License 2.0 | 4 votes |
@Override public long delete(WriteToken token, Metadata metadata, long start, long end) throws IOException { // // Regen classId/labelsId // // 128BITS metadata.setLabelsId(GTSHelper.labelsId(this.keystore.getKey(KeyStore.SIPHASH_LABELS), metadata.getLabels())); metadata.setClassId(GTSHelper.classId(this.keystore.getKey(KeyStore.SIPHASH_CLASS), metadata.getName())); // // Retrieve an iterator // DBIterator iterator = this.db.iterator(); // // Seek the most recent key // // 128BITS byte[] bend = new byte[Constants.HBASE_RAW_DATA_KEY_PREFIX.length + 8 + 8 + 8]; ByteBuffer bb = ByteBuffer.wrap(bend).order(ByteOrder.BIG_ENDIAN); bb.put(Constants.HBASE_RAW_DATA_KEY_PREFIX); bb.putLong(metadata.getClassId()); bb.putLong(metadata.getLabelsId()); bb.putLong(Long.MAX_VALUE - end); iterator.seek(bend); byte[] bstart = new byte[bend.length]; bb = ByteBuffer.wrap(bstart).order(ByteOrder.BIG_ENDIAN); bb.put(Constants.HBASE_RAW_DATA_KEY_PREFIX); bb.putLong(metadata.getClassId()); bb.putLong(metadata.getLabelsId()); bb.putLong(Long.MAX_VALUE - start); // // Scan the iterator, deleting keys if they are between start and end // long count = 0L; WriteBatch batch = this.db.createWriteBatch(); int batchsize = 0; WriteOptions options = new WriteOptions().sync(1.0 == syncrate); while (iterator.hasNext()) { Entry<byte[],byte[]> entry = iterator.next(); if (Bytes.compareTo(entry.getKey(), bend) >= 0 && Bytes.compareTo(entry.getKey(), bstart) <= 0) { batch.delete(entry.getKey()); batchsize++; if (MAX_DELETE_BATCHSIZE <= batchsize) { if (syncwrites) { options = new WriteOptions().sync(Math.random() < syncrate); } this.db.write(batch, options); batch.close(); batch = this.db.createWriteBatch(); batchsize = 0; } //this.db.delete(entry.getKey()); count++; } else { break; } } if (batchsize > 0) { if (syncwrites) { options = new WriteOptions().sync(Math.random() < syncrate); } this.db.write(batch, options); } iterator.close(); batch.close(); return count; }
Example #14
Source File: MockDB.java From ethereumj with MIT License | 4 votes |
@Override public Snapshot delete(byte[] arg0, WriteOptions arg1) throws DBException { // TODO Auto-generated method stub return null; }
Example #15
Source File: MockDB.java From ethereumj with MIT License | 4 votes |
@Override public Snapshot put(byte[] arg0, byte[] arg1, WriteOptions arg2) throws DBException { // TODO Auto-generated method stub return null; }
Example #16
Source File: MockDB.java From ethereumj with MIT License | 4 votes |
@Override public Snapshot write(WriteBatch arg0, WriteOptions arg1) throws DBException { // TODO Auto-generated method stub return null; }