Skip to content

Commit 0597949

Browse files
committed
[Java] Enable filluniquerandom, readseq, BloomFilter, and 70+ command-line options to DbBenchmark.java
Summary: * Add filluniquerandom * Add readseq, implemented using iterator. * Realize most command-line-arguments from db_bench.cc (70+). * Some code are commented out as some of the options in Options not yet have Java bindings. * Add default option to DbBenchmark. * RocksDB will now take the ownership of all c++ raw-pointers from Options, which includes a c++ raw-pointer for Filter. Test Plan: ./jdb_bench.sh --db=/tmp/rocksjava-bench/db --num_levels=6 --key_size=20 --prefix_size=20 --keys_per_prefix=0 --value_size=100 --block_size=4096 --cache_size=17179869184 --cache_numshardbits=6 --compression_ratio=1 --min_level_to_compress=-1 --disable_seek_compaction=1 --hard_rate_limit=2 --write_buffer_size=134217728 --max_write_buffer_number=2 --level0_file_num_compaction_trigger=8 --target_file_size_base=134217728 --max_bytes_for_level_base=1073741824 --disable_wal=0 --wal_dir=/tmp/rocksjava-bench/wal --sync=0 --disable_data_sync=1 --verify_checksum=1 --delete_obsolete_files_period_micros=314572800 --max_grandparent_overlap_factor=10 --max_background_compactions=4 --max_background_flushes=0 --level0_slowdown_writes_trigger=16 --level0_stop_writes_trigger=24 --statistics=0 --stats_per_interval=0 --stats_interval=1048576 --histogram=0 --use_plain_table=1 --open_files=-1 --mmap_read=1 --mmap_write=0 --memtablerep=prefix_hash --bloom_bits=10 --bloom_locality=1 --perf_level=0 --benchmarks=filluniquerandom,readseq,readrandom --use_existing_db=0 --threads=4 Reviewers: haobo, dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D18267
1 parent 4cd9f58 commit 0597949

File tree

6 files changed

+776
-70
lines changed

6 files changed

+776
-70
lines changed

java/org/rocksdb/Filter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class Filter {
2020
/**
2121
* Deletes underlying C++ filter pointer.
2222
*/
23-
public synchronized void dispose() {
23+
protected synchronized void dispose() {
2424
if(nativeHandle_ != 0) {
2525
dispose0(nativeHandle_);
2626
}

java/org/rocksdb/Options.java

+67-8
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,21 @@ public long blockSize() {
146146

147147
/**
148148
* Use the specified filter policy to reduce disk reads.
149+
*
150+
* Note that the caller should not dispose the input filter as
151+
* Options.dispose() will dispose this filter.
152+
*
149153
* @param Filter policy java instance.
150154
* @return the instance of the current Options.
151155
* @see RocksDB.open()
152156
*/
153157
public Options setFilter(Filter filter) {
154158
assert(isInitialized());
155-
setFilter0(nativeHandle_, filter);
159+
setFilterHandle(nativeHandle_, filter.nativeHandle_);
160+
filter_ = filter;
156161
return this;
157162
}
163+
private native void setFilterHandle(long optHandle, long filterHandle);
158164

159165
/*
160166
* Disable compaction triggered by seek.
@@ -786,7 +792,8 @@ private native void setTableCacheRemoveScanCountLimit(
786792
long handle, int limit);
787793

788794
/**
789-
* The following two fields affect how archived logs will be deleted.
795+
* WalTtlSeconds() and walSizeLimitMB() affect how archived logs
796+
* will be deleted.
790797
* 1. If both set to 0, logs will be deleted asap and will not get into
791798
* the archive.
792799
* 2. If WAL_ttl_seconds is 0 and WAL_size_limit_MB is not 0,
@@ -800,6 +807,7 @@ private native void setTableCacheRemoveScanCountLimit(
800807
* checks will be performed with ttl being first.
801808
*
802809
* @return the wal-ttl seconds
810+
* @see walSizeLimitMB()
803811
*/
804812
public long walTtlSeconds() {
805813
assert(isInitialized());
@@ -808,7 +816,8 @@ public long walTtlSeconds() {
808816
private native long walTtlSeconds(long handle);
809817

810818
/**
811-
* The following two fields affect how archived logs will be deleted.
819+
* WalTtlSeconds() and walSizeLimitMB() affect how archived logs
820+
* will be deleted.
812821
* 1. If both set to 0, logs will be deleted asap and will not get into
813822
* the archive.
814823
* 2. If WAL_ttl_seconds is 0 and WAL_size_limit_MB is not 0,
@@ -823,13 +832,64 @@ public long walTtlSeconds() {
823832
*
824833
* @param walTtlSeconds the ttl seconds
825834
* @return the reference to the current option.
835+
* @see setWalSizeLimitMB()
826836
*/
827-
public Options setWALTtlSeconds(long walTtlSeconds) {
837+
public Options setWalTtlSeconds(long walTtlSeconds) {
828838
assert(isInitialized());
829-
setWALTtlSeconds(nativeHandle_, walTtlSeconds);
839+
setWalTtlSeconds(nativeHandle_, walTtlSeconds);
830840
return this;
831841
}
832-
private native void setWALTtlSeconds(long handle, long walTtlSeconds);
842+
private native void setWalTtlSeconds(long handle, long walTtlSeconds);
843+
844+
/**
845+
* WalTtlSeconds() and walSizeLimitMB() affect how archived logs
846+
* will be deleted.
847+
* 1. If both set to 0, logs will be deleted asap and will not get into
848+
* the archive.
849+
* 2. If WAL_ttl_seconds is 0 and WAL_size_limit_MB is not 0,
850+
* WAL files will be checked every 10 min and if total size is greater
851+
* then WAL_size_limit_MB, they will be deleted starting with the
852+
* earliest until size_limit is met. All empty files will be deleted.
853+
* 3. If WAL_ttl_seconds is not 0 and WAL_size_limit_MB is 0, then
854+
* WAL files will be checked every WAL_ttl_secondsi / 2 and those that
855+
* are older than WAL_ttl_seconds will be deleted.
856+
* 4. If both are not 0, WAL files will be checked every 10 min and both
857+
* checks will be performed with ttl being first.
858+
*
859+
* @return size limit in mega-bytes.
860+
* @see walSizeLimitMB()
861+
*/
862+
public long walSizeLimitMB() {
863+
assert(isInitialized());
864+
return walSizeLimitMB(nativeHandle_);
865+
}
866+
private native long walSizeLimitMB(long handle);
867+
868+
/**
869+
* WalTtlSeconds() and walSizeLimitMB() affect how archived logs
870+
* will be deleted.
871+
* 1. If both set to 0, logs will be deleted asap and will not get into
872+
* the archive.
873+
* 2. If WAL_ttl_seconds is 0 and WAL_size_limit_MB is not 0,
874+
* WAL files will be checked every 10 min and if total size is greater
875+
* then WAL_size_limit_MB, they will be deleted starting with the
876+
* earliest until size_limit is met. All empty files will be deleted.
877+
* 3. If WAL_ttl_seconds is not 0 and WAL_size_limit_MB is 0, then
878+
* WAL files will be checked every WAL_ttl_secondsi / 2 and those that
879+
* are older than WAL_ttl_seconds will be deleted.
880+
* 4. If both are not 0, WAL files will be checked every 10 min and both
881+
* checks will be performed with ttl being first.
882+
*
883+
* @param sizeLimitMB size limit in mega-bytes.
884+
* @return the reference to the current option.
885+
* @see setWalSizeLimitMB()
886+
*/
887+
public Options setWalSizeLimitMB(long sizeLimitMB) {
888+
assert(isInitialized());
889+
setWalSizeLimitMB(nativeHandle_, sizeLimitMB);
890+
return this;
891+
}
892+
private native void setWalSizeLimitMB(long handle, long sizeLimitMB);
833893

834894
/**
835895
* Number of bytes to preallocate (via fallocate) the manifest
@@ -2298,8 +2358,7 @@ private native void setMaxBackgroundCompactions(
22982358
private native void useFixedLengthPrefixExtractor(
22992359
long handle, int prefixLength);
23002360

2301-
private native void setFilter0(long optHandle, Filter fp);
2302-
23032361
long nativeHandle_;
23042362
long cacheSize_;
2363+
Filter filter_;
23052364
}

java/org/rocksdb/RocksDB.java

+17
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static RocksDB open(String path) throws RocksDBException {
3636
// the c++ one.
3737
Options options = new Options();
3838
db.open(options.nativeHandle_, options.cacheSize_, path);
39+
db.transferCppRawPointersOwnership(options);
3940
options.dispose();
4041
return db;
4142
}
@@ -46,8 +47,12 @@ public static RocksDB open(String path) throws RocksDBException {
4647
*/
4748
public static RocksDB open(Options options, String path)
4849
throws RocksDBException {
50+
// when non-default Options is used, keeping an Options reference
51+
// in RocksDB can prevent Java to GC during the life-time of
52+
// the currently-created RocksDB.
4953
RocksDB db = new RocksDB();
5054
db.open(options.nativeHandle_, options.cacheSize_, path);
55+
db.transferCppRawPointersOwnershipFrom(options);
5156
return db;
5257
}
5358

@@ -195,6 +200,17 @@ protected RocksDB() {
195200
nativeHandle_ = 0;
196201
}
197202

203+
/**
204+
* Transfer the ownership of all c++ raw-pointers from Options
205+
* to RocksDB to ensure the life-time of those raw-pointers
206+
* will be at least as long as the life-time of any RocksDB
207+
* that uses these raw-pointers.
208+
*/
209+
protected void transferCppRawPointersOwnershipFrom(Options opt) {
210+
filter_ = opt.filter_;
211+
opt.filter_ = null;
212+
}
213+
198214
// native methods
199215
protected native void open(
200216
long optionsHandle, long cacheSize, String path) throws RocksDBException;
@@ -227,4 +243,5 @@ protected native void remove(
227243
protected native void close0();
228244

229245
protected long nativeHandle_;
246+
protected Filter filter_;
230247
}

0 commit comments

Comments
 (0)