commit
625e162c69
@ -0,0 +1,51 @@ |
|||||||
|
package org.rocksdb; |
||||||
|
|
||||||
|
/** |
||||||
|
* FlushOptions to be passed to flush operations of |
||||||
|
* {@link org.rocksdb.RocksDB}. |
||||||
|
*/ |
||||||
|
public class FlushOptions extends RocksObject { |
||||||
|
|
||||||
|
/** |
||||||
|
* Construct a new instance of FlushOptions. |
||||||
|
*/ |
||||||
|
public FlushOptions(){ |
||||||
|
super(); |
||||||
|
newFlushOptions(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set if the flush operation shall block until it terminates. |
||||||
|
* |
||||||
|
* @param waitForFlush boolean value indicating if the flush |
||||||
|
* operations waits for termination of the flush process. |
||||||
|
* |
||||||
|
* @return instance of current FlushOptions. |
||||||
|
*/ |
||||||
|
public FlushOptions setWaitForFlush(boolean waitForFlush) { |
||||||
|
assert(isInitialized()); |
||||||
|
waitForFlush(nativeHandle_); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Wait for flush to finished. |
||||||
|
* |
||||||
|
* @return boolean value indicating if the flush operation |
||||||
|
* waits for termination of the flush process. |
||||||
|
*/ |
||||||
|
public boolean waitForFlush() { |
||||||
|
assert(isInitialized()); |
||||||
|
return waitForFlush(nativeHandle_); |
||||||
|
} |
||||||
|
|
||||||
|
@Override protected void disposeInternal() { |
||||||
|
disposeInternal(nativeHandle_); |
||||||
|
} |
||||||
|
|
||||||
|
private native void newFlushOptions(); |
||||||
|
private native void disposeInternal(long handle); |
||||||
|
private native void setWaitForFlush(long handle, |
||||||
|
boolean wait); |
||||||
|
private native boolean waitForFlush(long handle); |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
package org.rocksdb.test; |
||||||
|
|
||||||
|
import org.rocksdb.*; |
||||||
|
|
||||||
|
public class FlushTest { |
||||||
|
|
||||||
|
static final String db_path = "/tmp/rocksdbjni_flush_test"; |
||||||
|
static { |
||||||
|
RocksDB.loadLibrary(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
RocksDB db = null; |
||||||
|
Options options = new Options(); |
||||||
|
WriteOptions wOpt = new WriteOptions(); |
||||||
|
FlushOptions flushOptions = new FlushOptions(); |
||||||
|
|
||||||
|
try { |
||||||
|
// Setup options
|
||||||
|
options.setCreateIfMissing(true); |
||||||
|
options.setMaxWriteBufferNumber(10); |
||||||
|
options.setMinWriteBufferNumberToMerge(10); |
||||||
|
flushOptions.setWaitForFlush(true); |
||||||
|
wOpt.setDisableWAL(true); |
||||||
|
db = RocksDB.open(options, db_path); |
||||||
|
|
||||||
|
db.put(wOpt, "key1".getBytes(), "value1".getBytes()); |
||||||
|
db.put(wOpt, "key2".getBytes(), "value2".getBytes()); |
||||||
|
db.put(wOpt, "key3".getBytes(), "value3".getBytes()); |
||||||
|
db.put(wOpt, "key4".getBytes(), "value4".getBytes()); |
||||||
|
assert(db.getProperty("rocksdb.num-entries-active-mem-table").equals("4")); |
||||||
|
db.flush(flushOptions); |
||||||
|
assert(db.getProperty("rocksdb.num-entries-active-mem-table").equals("0")); |
||||||
|
} catch (RocksDBException e) { |
||||||
|
assert(false); |
||||||
|
} |
||||||
|
|
||||||
|
db.close(); |
||||||
|
options.dispose(); |
||||||
|
wOpt.dispose(); |
||||||
|
flushOptions.dispose(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue