public void run() { FlushOptions fo = new FlushOptions(); fo.setWaitForFlush(true); try { finalDB.flush(fo); } catch (RocksDBException e) { LOGGER.warn("RocksDB flush error", e); } finally { finalDB.close(); fo.close(); options.close(); } } });
@Override public void flush() { try { for(Map.Entry<ByteArray, Map<ByteArray, byte[]>> entry: dataBatches.entrySet()) { WriteBatch writeBatch = new WriteBatch(); WriteOptions writeOptions = new WriteOptions().setDisableWAL(true); for(Map.Entry<ByteArray, byte[]> batchEntry: entry.getValue().entrySet()) { writeBatch.put( cfHandles.get(entry.getKey()), batchEntry.getKey().getBytes(), batchEntry.getValue() ); } rocksDB.write(writeOptions, writeBatch); writeBatch.close(); writeOptions.close(); entry.getValue().clear(); } FlushOptions fOptions = new FlushOptions().setWaitForFlush(true); rocksDB.flush(fOptions); fOptions.close(); } catch(RocksDBException ex) { throw new RuntimeException(ex); } }
@Override public void flush(String keySpace) { Preconditions.checkNotNull(keySpace); ByteArray byteArray = new ByteArray(keySpace); try { WriteBatch writeBatch = new WriteBatch(); WriteOptions writeOptions = new WriteOptions().setDisableWAL(true); for(Map.Entry<ByteArray, byte[]> entry: dataBatches.get(byteArray).entrySet()) { writeBatch.put( cfHandles.get(byteArray), entry.getKey().getBytes(), entry.getValue() ); } rocksDB.write(writeOptions, writeBatch); writeBatch.close(); writeOptions.close(); dataBatches.get(byteArray).clear(); FlushOptions fOptions = new FlushOptions().setWaitForFlush(true); rocksDB.flush(new FlushOptions(), cfHandles.get(byteArray)); fOptions.close(); } catch(RocksDBException ex) { throw new RuntimeException(ex); } }
@Override public synchronized void close() { if (!open) { return; } open = false; closeOpenIterators(); options.close(); wOptions.close(); fOptions.close(); db.close(); options = null; wOptions = null; fOptions = null; db = null; }