Skip to content

Commit 2885ad9

Browse files
committed
[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
1 parent be01661 commit 2885ad9

File tree

3 files changed

+55
-31
lines changed

3 files changed

+55
-31
lines changed

java/RocksDBSample.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public static void main(String[] args) {
3232
assert(db == null);
3333
}
3434

35-
options.setCreateIfMissing(true);
36-
options.setWriteBufferSize(8*1024);
37-
options.setMaxWriteBufferNumber(3);
38-
options.setDisableSeekCompaction(true);
39-
options.setBlockSize(64*1024);
40-
options.setMaxBackgroundCompactions(10);
35+
options.setCreateIfMissing(true)
36+
.setWriteBufferSize(8 * 1024)
37+
.setMaxWriteBufferNumber(3)
38+
.setDisableSeekCompaction(true)
39+
.setBlockSize(64 * 1024)
40+
.setMaxBackgroundCompactions(10);
4141

4242
assert(options.createIfMissing() == true);
4343
assert(options.writeBufferSize() == 8192);

java/org/rocksdb/Options.java

+36-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* Options to control the behavior of a database. It will be used
10-
* during the creation of a RocksDB (i.e., RocksDB::Open()).
10+
* during the creation of a RocksDB (i.e., RocksDB.open()).
1111
*
1212
* Note that dispose() must be called before an Options instance
1313
* become out-of-scope to release the allocated memory in c++.
@@ -26,23 +26,25 @@ public Options() {
2626

2727
/**
2828
* If this value is set to true, then the database will be created
29-
* if it is missing during RocksDB::Open().
29+
* if it is missing during RocksDB.open().
3030
* Default: false
3131
*
3232
* @param flag a flag indicating whether to create a database the
33-
* specified database in RocksDB::Open() operation is missing.
34-
* @see RocksDB::Open()
33+
* specified database in RocksDB.open() operation is missing.
34+
* @return the instance of the current Options.
35+
* @see RocksDB.open()
3536
*/
36-
public void setCreateIfMissing(boolean flag) {
37+
public Options setCreateIfMissing(boolean flag) {
3738
assert(isInitialized());
3839
setCreateIfMissing(nativeHandle_, flag);
40+
return this;
3941
}
4042

4143
/**
4244
* Return true if the create_if_missing flag is set to true.
4345
* If true, the database will be created if it is missing.
4446
*
45-
* @return return true if the create_if_missing flag is set to true.
47+
* @return true if the createIfMissing option is set to true.
4648
* @see setCreateIfMissing()
4749
*/
4850
public boolean createIfMissing() {
@@ -63,12 +65,14 @@ public boolean createIfMissing() {
6365
* the next time the database is opened.
6466
*
6567
* Default: 4MB
66-
* @param size of write buffer.
67-
* @see RocksDB::Open()
68+
* @param writeBufferSize the size of write buffer.
69+
* @return the instance of the current Options.
70+
* @see RocksDB.open()
6871
*/
69-
public void setWriteBufferSize(int writeBufferSize) {
72+
public Options setWriteBufferSize(int writeBufferSize) {
7073
assert(isInitialized());
7174
setWriteBufferSize(nativeHandle_, writeBufferSize);
75+
return this;
7276
}
7377

7478
/**
@@ -88,12 +92,14 @@ public int writeBufferSize() {
8892
* storage, new writes can continue to the other write buffer.
8993
* Default: 2
9094
*
91-
* @param maximum number of write buffers.
92-
* @see RocksDB::Open()
95+
* @param maxWriteBufferNumber maximum number of write buffers.
96+
* @return the instance of the current Options.
97+
* @see RocksDB.open()
9398
*/
94-
public void setMaxWriteBufferNumber(int maxWriteBufferNumber) {
99+
public Options setMaxWriteBufferNumber(int maxWriteBufferNumber) {
95100
assert(isInitialized());
96101
setMaxWriteBufferNumber(nativeHandle_, maxWriteBufferNumber);
102+
return this;
97103
}
98104

99105
/**
@@ -115,16 +121,18 @@ public int maxWriteBufferNumber() {
115121
*
116122
* Default: 4K
117123
*
118-
* @param block size.
119-
* @see RocksDB::Open()
124+
* @param blockSize the size of each block in bytes.
125+
* @return the instance of the current Options.
126+
* @see RocksDB.open()
120127
*/
121-
public void setBlockSize(int blockSize) {
128+
public Options setBlockSize(int blockSize) {
122129
assert(isInitialized());
123130
setBlockSize(nativeHandle_, blockSize);
131+
return this;
124132
}
125133

126134
/*
127-
* Returns block size.
135+
* Returns the size of a block in bytes.
128136
*
129137
* @return block size.
130138
* @see setBlockSize()
@@ -141,12 +149,15 @@ public int blockSize() {
141149
* (which is true if max_open_files is large).
142150
* Default: true
143151
*
144-
* @param disable seek compaction.
145-
* @see RocksDB::Open()
152+
* @param disableSeekCompaction a boolean value to specify whether
153+
* to disable seek compaction.
154+
* @return the instance of the current Options.
155+
* @see RocksDB.open()
146156
*/
147-
public void setDisableSeekCompaction(boolean disableSeekCompaction) {
157+
public Options setDisableSeekCompaction(boolean disableSeekCompaction) {
148158
assert(isInitialized());
149159
setDisableSeekCompaction(nativeHandle_, disableSeekCompaction);
160+
return this;
150161
}
151162

152163
/*
@@ -165,12 +176,15 @@ public boolean disableSeekCompaction() {
165176
* the default LOW priority thread pool.
166177
* Default: 1
167178
*
168-
* @param maximum number of concurrent background jobs.
169-
* @see RocksDB::Open()
179+
* @param maxBackgroundCompactions the maximum number of concurrent
180+
* background jobs.
181+
* @return the instance of the current Options.
182+
* @see RocksDB.open()
170183
*/
171-
public void setMaxBackgroundCompactions(int maxBackgroundCompactions) {
184+
public Options setMaxBackgroundCompactions(int maxBackgroundCompactions) {
172185
assert(isInitialized());
173186
setMaxBackgroundCompactions(nativeHandle_, maxBackgroundCompactions);
187+
return this;
174188
}
175189

176190
/*

java/org/rocksdb/WriteOptions.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ public synchronized void dispose() {
4040
* system call followed by "fdatasync()".
4141
*
4242
* Default: false
43+
*
44+
* @param flag a boolean flag to indicate whether a write
45+
* should be synchronized.
46+
* @return the instance of the current WriteOptions.
4347
*/
44-
public void setSync(boolean flag) {
48+
public WriteOptions setSync(boolean flag) {
4549
setSync(nativeHandle_, flag);
50+
return this;
4651
}
4752

4853
/**
@@ -68,9 +73,14 @@ public boolean sync() {
6873
/**
6974
* If true, writes will not first go to the write ahead log,
7075
* and the write may got lost after a crash.
76+
*
77+
* @param flag a boolean flag to specify whether to disable
78+
* write-ahead-log on writes.
79+
* @return the instance of the current WriteOptions.
7180
*/
72-
public void setDisableWAL(boolean flag) {
81+
public WriteOptions setDisableWAL(boolean flag) {
7382
setDisableWAL(nativeHandle_, flag);
83+
return this;
7484
}
7585

7686
/**
@@ -92,5 +102,5 @@ public boolean disableWAL() {
92102
private native boolean disableWAL(long handle);
93103
private native void dispose0(long handle);
94104

95-
protected long nativeHandle_;
105+
protected long nativeHandle_;
96106
}

0 commit comments

Comments
 (0)