[JNI] Each set function of Options / WriteOptions now returns its option instance.
Summary: Make each set function of Options / WriteOptions return its option instance. Java developers can now easier specify each option like the following: options.setCreateIfMissing(true) .setWriteBufferSize(8 * 1024) .setMaxWriteBufferNumber(3) .setDisableSeekCompaction(true) .setBlockSize(64 * 1024) .setMaxBackgroundCompactions(10); Test Plan: make rocksdbjava make jtest Reviewers: haobo, ankgup87, sdong, dhruba Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D17661
This commit is contained in:
parent
be016613c2
commit
2885ad9b77
@ -32,12 +32,12 @@ public class RocksDBSample {
|
|||||||
assert(db == null);
|
assert(db == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
options.setCreateIfMissing(true);
|
options.setCreateIfMissing(true)
|
||||||
options.setWriteBufferSize(8*1024);
|
.setWriteBufferSize(8 * 1024)
|
||||||
options.setMaxWriteBufferNumber(3);
|
.setMaxWriteBufferNumber(3)
|
||||||
options.setDisableSeekCompaction(true);
|
.setDisableSeekCompaction(true)
|
||||||
options.setBlockSize(64*1024);
|
.setBlockSize(64 * 1024)
|
||||||
options.setMaxBackgroundCompactions(10);
|
.setMaxBackgroundCompactions(10);
|
||||||
|
|
||||||
assert(options.createIfMissing() == true);
|
assert(options.createIfMissing() == true);
|
||||||
assert(options.writeBufferSize() == 8192);
|
assert(options.writeBufferSize() == 8192);
|
||||||
|
@ -7,7 +7,7 @@ package org.rocksdb;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Options to control the behavior of a database. It will be used
|
* Options to control the behavior of a database. It will be used
|
||||||
* during the creation of a RocksDB (i.e., RocksDB::Open()).
|
* during the creation of a RocksDB (i.e., RocksDB.open()).
|
||||||
*
|
*
|
||||||
* Note that dispose() must be called before an Options instance
|
* Note that dispose() must be called before an Options instance
|
||||||
* become out-of-scope to release the allocated memory in c++.
|
* become out-of-scope to release the allocated memory in c++.
|
||||||
@ -26,23 +26,25 @@ public class Options {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If this value is set to true, then the database will be created
|
* If this value is set to true, then the database will be created
|
||||||
* if it is missing during RocksDB::Open().
|
* if it is missing during RocksDB.open().
|
||||||
* Default: false
|
* Default: false
|
||||||
*
|
*
|
||||||
* @param flag a flag indicating whether to create a database the
|
* @param flag a flag indicating whether to create a database the
|
||||||
* specified database in RocksDB::Open() operation is missing.
|
* specified database in RocksDB.open() operation is missing.
|
||||||
* @see RocksDB::Open()
|
* @return the instance of the current Options.
|
||||||
|
* @see RocksDB.open()
|
||||||
*/
|
*/
|
||||||
public void setCreateIfMissing(boolean flag) {
|
public Options setCreateIfMissing(boolean flag) {
|
||||||
assert(isInitialized());
|
assert(isInitialized());
|
||||||
setCreateIfMissing(nativeHandle_, flag);
|
setCreateIfMissing(nativeHandle_, flag);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the create_if_missing flag is set to true.
|
* Return true if the create_if_missing flag is set to true.
|
||||||
* If true, the database will be created if it is missing.
|
* If true, the database will be created if it is missing.
|
||||||
*
|
*
|
||||||
* @return return true if the create_if_missing flag is set to true.
|
* @return true if the createIfMissing option is set to true.
|
||||||
* @see setCreateIfMissing()
|
* @see setCreateIfMissing()
|
||||||
*/
|
*/
|
||||||
public boolean createIfMissing() {
|
public boolean createIfMissing() {
|
||||||
@ -63,12 +65,14 @@ public class Options {
|
|||||||
* the next time the database is opened.
|
* the next time the database is opened.
|
||||||
*
|
*
|
||||||
* Default: 4MB
|
* Default: 4MB
|
||||||
* @param size of write buffer.
|
* @param writeBufferSize the size of write buffer.
|
||||||
* @see RocksDB::Open()
|
* @return the instance of the current Options.
|
||||||
|
* @see RocksDB.open()
|
||||||
*/
|
*/
|
||||||
public void setWriteBufferSize(int writeBufferSize) {
|
public Options setWriteBufferSize(int writeBufferSize) {
|
||||||
assert(isInitialized());
|
assert(isInitialized());
|
||||||
setWriteBufferSize(nativeHandle_, writeBufferSize);
|
setWriteBufferSize(nativeHandle_, writeBufferSize);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,12 +92,14 @@ public class Options {
|
|||||||
* storage, new writes can continue to the other write buffer.
|
* storage, new writes can continue to the other write buffer.
|
||||||
* Default: 2
|
* Default: 2
|
||||||
*
|
*
|
||||||
* @param maximum number of write buffers.
|
* @param maxWriteBufferNumber maximum number of write buffers.
|
||||||
* @see RocksDB::Open()
|
* @return the instance of the current Options.
|
||||||
|
* @see RocksDB.open()
|
||||||
*/
|
*/
|
||||||
public void setMaxWriteBufferNumber(int maxWriteBufferNumber) {
|
public Options setMaxWriteBufferNumber(int maxWriteBufferNumber) {
|
||||||
assert(isInitialized());
|
assert(isInitialized());
|
||||||
setMaxWriteBufferNumber(nativeHandle_, maxWriteBufferNumber);
|
setMaxWriteBufferNumber(nativeHandle_, maxWriteBufferNumber);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,16 +121,18 @@ public class Options {
|
|||||||
*
|
*
|
||||||
* Default: 4K
|
* Default: 4K
|
||||||
*
|
*
|
||||||
* @param block size.
|
* @param blockSize the size of each block in bytes.
|
||||||
* @see RocksDB::Open()
|
* @return the instance of the current Options.
|
||||||
|
* @see RocksDB.open()
|
||||||
*/
|
*/
|
||||||
public void setBlockSize(int blockSize) {
|
public Options setBlockSize(int blockSize) {
|
||||||
assert(isInitialized());
|
assert(isInitialized());
|
||||||
setBlockSize(nativeHandle_, blockSize);
|
setBlockSize(nativeHandle_, blockSize);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns block size.
|
* Returns the size of a block in bytes.
|
||||||
*
|
*
|
||||||
* @return block size.
|
* @return block size.
|
||||||
* @see setBlockSize()
|
* @see setBlockSize()
|
||||||
@ -141,12 +149,15 @@ public class Options {
|
|||||||
* (which is true if max_open_files is large).
|
* (which is true if max_open_files is large).
|
||||||
* Default: true
|
* Default: true
|
||||||
*
|
*
|
||||||
* @param disable seek compaction.
|
* @param disableSeekCompaction a boolean value to specify whether
|
||||||
* @see RocksDB::Open()
|
* to disable seek compaction.
|
||||||
|
* @return the instance of the current Options.
|
||||||
|
* @see RocksDB.open()
|
||||||
*/
|
*/
|
||||||
public void setDisableSeekCompaction(boolean disableSeekCompaction) {
|
public Options setDisableSeekCompaction(boolean disableSeekCompaction) {
|
||||||
assert(isInitialized());
|
assert(isInitialized());
|
||||||
setDisableSeekCompaction(nativeHandle_, disableSeekCompaction);
|
setDisableSeekCompaction(nativeHandle_, disableSeekCompaction);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -165,12 +176,15 @@ public class Options {
|
|||||||
* the default LOW priority thread pool.
|
* the default LOW priority thread pool.
|
||||||
* Default: 1
|
* Default: 1
|
||||||
*
|
*
|
||||||
* @param maximum number of concurrent background jobs.
|
* @param maxBackgroundCompactions the maximum number of concurrent
|
||||||
* @see RocksDB::Open()
|
* background jobs.
|
||||||
|
* @return the instance of the current Options.
|
||||||
|
* @see RocksDB.open()
|
||||||
*/
|
*/
|
||||||
public void setMaxBackgroundCompactions(int maxBackgroundCompactions) {
|
public Options setMaxBackgroundCompactions(int maxBackgroundCompactions) {
|
||||||
assert(isInitialized());
|
assert(isInitialized());
|
||||||
setMaxBackgroundCompactions(nativeHandle_, maxBackgroundCompactions);
|
setMaxBackgroundCompactions(nativeHandle_, maxBackgroundCompactions);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -40,9 +40,14 @@ public class WriteOptions {
|
|||||||
* system call followed by "fdatasync()".
|
* system call followed by "fdatasync()".
|
||||||
*
|
*
|
||||||
* Default: false
|
* Default: false
|
||||||
|
*
|
||||||
|
* @param flag a boolean flag to indicate whether a write
|
||||||
|
* should be synchronized.
|
||||||
|
* @return the instance of the current WriteOptions.
|
||||||
*/
|
*/
|
||||||
public void setSync(boolean flag) {
|
public WriteOptions setSync(boolean flag) {
|
||||||
setSync(nativeHandle_, flag);
|
setSync(nativeHandle_, flag);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,9 +73,14 @@ public class WriteOptions {
|
|||||||
/**
|
/**
|
||||||
* If true, writes will not first go to the write ahead log,
|
* If true, writes will not first go to the write ahead log,
|
||||||
* and the write may got lost after a crash.
|
* and the write may got lost after a crash.
|
||||||
|
*
|
||||||
|
* @param flag a boolean flag to specify whether to disable
|
||||||
|
* write-ahead-log on writes.
|
||||||
|
* @return the instance of the current WriteOptions.
|
||||||
*/
|
*/
|
||||||
public void setDisableWAL(boolean flag) {
|
public WriteOptions setDisableWAL(boolean flag) {
|
||||||
setDisableWAL(nativeHandle_, flag);
|
setDisableWAL(nativeHandle_, flag);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,5 +102,5 @@ public class WriteOptions {
|
|||||||
private native boolean disableWAL(long handle);
|
private native boolean disableWAL(long handle);
|
||||||
private native void dispose0(long handle);
|
private native void dispose0(long handle);
|
||||||
|
|
||||||
protected long nativeHandle_;
|
protected long nativeHandle_;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user