/** * If true, the write will be flushed from the operating system * buffer cache (by calling WritableFile::Sync()) before the write * is considered complete. If this flag is true, writes will be * slower. * * If this flag is false, and the machine crashes, some recent * writes may be lost. Note that if it is just the process that * crashes (i.e., the machine does not reboot), no writes will be * lost even if sync==false. * * In other words, a DB write with sync==false has similar * crash semantics as the "write()" system call. A DB write * with sync==true has similar crash semantics to a "write()" * system call followed by "fdatasync()". * * @return boolean value indicating if sync is active. */ public boolean sync() { return sync(nativeHandle_); }
private void putAll() { if (putBuffer.size() > 0) { Iterator<Entry<K, V>> iterator = putBuffer.entrySet().iterator(); try (WriteOptions wo = new WriteOptions()) { wo.setDisableWAL(true); wo.setSync(false); try (WriteBatch batch = new WriteBatch()) { while (iterator.hasNext()) { try (ByteArrayOutputStream keyBytes = new ByteArrayOutputStream(); ObjectOutput keyOut = new ObjectOutputStream(keyBytes); ByteArrayOutputStream valueBytes = new ByteArrayOutputStream(); ObjectOutput valueOut = new ObjectOutputStream(valueBytes);) { Entry<K, V> object = iterator.next(); keyOut.writeObject(object.getKey()); valueOut.writeObject(object.getValue()); keyOut.flush(); valueOut.flush(); batch.put(keyBytes.toByteArray(), valueBytes.toByteArray()); } } db.write(wo, batch); } wo.sync(); } catch (IOException | RocksDBException e) { throw Throwables.propagate(e); } putBuffer.clear(); } }