From 2885ad9b77897932a9c63c97cfaaffdb72e4b64f Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Mon, 14 Apr 2014 12:48:50 -0700 Subject: [PATCH] [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 --- java/RocksDBSample.java | 12 +++---- java/org/rocksdb/Options.java | 58 ++++++++++++++++++------------ java/org/rocksdb/WriteOptions.java | 16 +++++++-- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/java/RocksDBSample.java b/java/RocksDBSample.java index a457701a5..98b9fa770 100644 --- a/java/RocksDBSample.java +++ b/java/RocksDBSample.java @@ -32,12 +32,12 @@ public class RocksDBSample { assert(db == null); } - options.setCreateIfMissing(true); - options.setWriteBufferSize(8*1024); - options.setMaxWriteBufferNumber(3); - options.setDisableSeekCompaction(true); - options.setBlockSize(64*1024); - options.setMaxBackgroundCompactions(10); + options.setCreateIfMissing(true) + .setWriteBufferSize(8 * 1024) + .setMaxWriteBufferNumber(3) + .setDisableSeekCompaction(true) + .setBlockSize(64 * 1024) + .setMaxBackgroundCompactions(10); assert(options.createIfMissing() == true); assert(options.writeBufferSize() == 8192); diff --git a/java/org/rocksdb/Options.java b/java/org/rocksdb/Options.java index b93ffb128..343533be2 100644 --- a/java/org/rocksdb/Options.java +++ b/java/org/rocksdb/Options.java @@ -7,7 +7,7 @@ package org.rocksdb; /** * 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 * 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 it is missing during RocksDB::Open(). + * if it is missing during RocksDB.open(). * Default: false * * @param flag a flag indicating whether to create a database the - * specified database in RocksDB::Open() operation is missing. - * @see RocksDB::Open() + * specified database in RocksDB.open() operation is missing. + * @return the instance of the current Options. + * @see RocksDB.open() */ - public void setCreateIfMissing(boolean flag) { + public Options setCreateIfMissing(boolean flag) { assert(isInitialized()); setCreateIfMissing(nativeHandle_, flag); + return this; } /** * Return true if the create_if_missing flag is set to true. * 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() */ public boolean createIfMissing() { @@ -63,12 +65,14 @@ public class Options { * the next time the database is opened. * * Default: 4MB - * @param size of write buffer. - * @see RocksDB::Open() + * @param writeBufferSize the size of write buffer. + * @return the instance of the current Options. + * @see RocksDB.open() */ - public void setWriteBufferSize(int writeBufferSize) { + public Options setWriteBufferSize(int writeBufferSize) { assert(isInitialized()); setWriteBufferSize(nativeHandle_, writeBufferSize); + return this; } /** @@ -88,12 +92,14 @@ public class Options { * storage, new writes can continue to the other write buffer. * Default: 2 * - * @param maximum number of write buffers. - * @see RocksDB::Open() + * @param maxWriteBufferNumber maximum number of write buffers. + * @return the instance of the current Options. + * @see RocksDB.open() */ - public void setMaxWriteBufferNumber(int maxWriteBufferNumber) { + public Options setMaxWriteBufferNumber(int maxWriteBufferNumber) { assert(isInitialized()); setMaxWriteBufferNumber(nativeHandle_, maxWriteBufferNumber); + return this; } /** @@ -115,16 +121,18 @@ public class Options { * * Default: 4K * - * @param block size. - * @see RocksDB::Open() + * @param blockSize the size of each block in bytes. + * @return the instance of the current Options. + * @see RocksDB.open() */ - public void setBlockSize(int blockSize) { + public Options setBlockSize(int blockSize) { assert(isInitialized()); setBlockSize(nativeHandle_, blockSize); + return this; } /* - * Returns block size. + * Returns the size of a block in bytes. * * @return block size. * @see setBlockSize() @@ -141,12 +149,15 @@ public class Options { * (which is true if max_open_files is large). * Default: true * - * @param disable seek compaction. - * @see RocksDB::Open() + * @param disableSeekCompaction a boolean value to specify whether + * 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()); setDisableSeekCompaction(nativeHandle_, disableSeekCompaction); + return this; } /* @@ -165,12 +176,15 @@ public class Options { * the default LOW priority thread pool. * Default: 1 * - * @param maximum number of concurrent background jobs. - * @see RocksDB::Open() + * @param maxBackgroundCompactions the maximum number of concurrent + * background jobs. + * @return the instance of the current Options. + * @see RocksDB.open() */ - public void setMaxBackgroundCompactions(int maxBackgroundCompactions) { + public Options setMaxBackgroundCompactions(int maxBackgroundCompactions) { assert(isInitialized()); setMaxBackgroundCompactions(nativeHandle_, maxBackgroundCompactions); + return this; } /* diff --git a/java/org/rocksdb/WriteOptions.java b/java/org/rocksdb/WriteOptions.java index 26f0e2b7c..aa7a73164 100644 --- a/java/org/rocksdb/WriteOptions.java +++ b/java/org/rocksdb/WriteOptions.java @@ -40,9 +40,14 @@ public class WriteOptions { * system call followed by "fdatasync()". * * 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); + return this; } /** @@ -68,9 +73,14 @@ public class WriteOptions { /** * If true, writes will not first go to the write ahead log, * 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); + return this; } /** @@ -92,5 +102,5 @@ public class WriteOptions { private native boolean disableWAL(long handle); private native void dispose0(long handle); - protected long nativeHandle_; + protected long nativeHandle_; }