Skip to content

Commit 9895465

Browse files
committed
[Java] Fixed compile error due to the removal of ReadOptions.prefix_seek, minor improvement on DbBenchmark.java.
1 parent 7ca06a3 commit 9895465

File tree

6 files changed

+56
-69
lines changed

6 files changed

+56
-69
lines changed

java/jdb_bench.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
java -Djava.library.path=.:../ -cp "rocksdbjni.jar:.:./*" org.rocksdb.benchmark.DbBenchmark $@
1+
java -server -d64 -XX:NewSize=4m -XX:+AggressiveOpts -Djava.library.path=.:../ -cp "rocksdbjni.jar:.:./*" org.rocksdb.benchmark.DbBenchmark $@

java/org/rocksdb/ReadOptions.java

-28
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,6 @@ public ReadOptions setFillCache(boolean fillCache) {
9393
private native void setFillCache(
9494
long handle, boolean fillCache);
9595

96-
/**
97-
* If this option is set and memtable implementation allows, Seek
98-
* might only return keys with the same prefix as the seek-key
99-
* Default: false
100-
*
101-
* @return true if prefix-seek is enabled.
102-
*/
103-
public boolean prefixSeek() {
104-
assert(isInitialized());
105-
return prefixSeek(nativeHandle_);
106-
}
107-
private native boolean prefixSeek(long handle);
108-
109-
/**
110-
* If this option is set and memtable implementation allows, Seek
111-
* might only return keys with the same prefix as the seek-key
112-
*
113-
* @param prefixSeek if true, then prefix-seek will be enabled.
114-
* @return the reference to the current ReadOptions.
115-
*/
116-
public ReadOptions setPrefixSeek(boolean prefixSeek) {
117-
assert(isInitialized());
118-
setPrefixSeek(nativeHandle_, prefixSeek);
119-
return this;
120-
}
121-
private native void setPrefixSeek(
122-
long handle, boolean prefixSeek);
123-
12496
/**
12597
* Specify to create a tailing iterator -- a special iterator that has a
12698
* view of the complete database (i.e. it can also be used to read newly

java/org/rocksdb/benchmark/DbBenchmark.java

+54-12
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ enum DBState {
162162
EXISTING
163163
}
164164

165+
enum CompressionType {
166+
NONE,
167+
SNAPPY,
168+
ZLIB,
169+
BZIP2,
170+
LZ4,
171+
LZ4HC
172+
}
173+
165174
static {
166175
System.loadLibrary("rocksdbjni");
167176
}
@@ -435,7 +444,6 @@ public DbBenchmark(Map<Flag, Object> flags) throws Exception {
435444
databaseDir_ = (String) flags.get(Flag.db);
436445
writesPerSeconds_ = (Integer) flags.get(Flag.writes_per_second);
437446
cacheSize_ = (Long) flags.get(Flag.cache_size);
438-
gen_ = new RandomGenerator(randSeed_, compressionRatio_);
439447
memtable_ = (String) flags.get(Flag.memtablerep);
440448
maxWriteBufferNumber_ = (Integer) flags.get(Flag.max_write_buffer_number);
441449
prefixSize_ = (Integer) flags.get(Flag.prefix_size);
@@ -446,6 +454,28 @@ public DbBenchmark(Map<Flag, Object> flags) throws Exception {
446454
finishLock_ = new Object();
447455
// options.setPrefixSize((Integer)flags_.get(Flag.prefix_size));
448456
// options.setKeysPerPrefix((Long)flags_.get(Flag.keys_per_prefix));
457+
compressionType_ = (String) flags.get(Flag.compression_type);
458+
compression_ = CompressionType.NONE;
459+
try {
460+
if (compressionType_.equals("snappy")) {
461+
System.loadLibrary("snappy");
462+
} else if (compressionType_.equals("zlib")) {
463+
System.loadLibrary("zlib");
464+
} else if (compressionType_.equals("bzip2")) {
465+
System.loadLibrary("bzip2");
466+
} else if (compressionType_.equals("lz4")) {
467+
System.loadLibrary("lz4");
468+
} else if (compressionType_.equals("lz4hc")) {
469+
System.loadLibrary("lz4hc");
470+
}
471+
} catch (UnsatisfiedLinkError e) {
472+
System.err.format("Unable to load %s library:%s%n" +
473+
"No compression is used.%n",
474+
compressionType_, e.toString());
475+
compressionType_ = "none";
476+
compressionRatio_ = 1.0;
477+
}
478+
gen_ = new RandomGenerator(randSeed_, compressionRatio_);
449479
}
450480

451481
private void prepareReadOptions(ReadOptions options) {
@@ -462,6 +492,8 @@ private void prepareOptions(Options options) {
462492
options.setCacheSize(cacheSize_);
463493
if (!useExisting_) {
464494
options.setCreateIfMissing(true);
495+
} else {
496+
options.setCreateIfMissing(false);
465497
}
466498
if (memtable_.equals("skip_list")) {
467499
options.setMemTableConfig(new SkipListMemTableConfig());
@@ -488,6 +520,8 @@ private void prepareOptions(Options options) {
488520
options.setTableFormatConfig(
489521
new PlainTableConfig().setKeySize(keySize_));
490522
}
523+
options.setWriteBufferSize(
524+
(Long)flags_.get(Flag.write_buffer_size));
491525
options.setMaxWriteBufferNumber(
492526
(Integer)flags_.get(Flag.max_write_buffer_number));
493527
options.setMaxBackgroundCompactions(
@@ -513,7 +547,7 @@ private void prepareOptions(Options options) {
513547
options.setDisableSeekCompaction(
514548
(Boolean)flags_.get(Flag.disable_seek_compaction));
515549
options.setDeleteObsoleteFilesPeriodMicros(
516-
(Long)flags_.get(Flag.delete_obsolete_files_period_micros));
550+
(Integer)flags_.get(Flag.delete_obsolete_files_period_micros));
517551
options.setTableCacheNumshardbits(
518552
(Integer)flags_.get(Flag.table_cache_numshardbits));
519553
options.setAllowMmapReads(
@@ -640,12 +674,12 @@ private void run() throws RocksDBException {
640674
} else if (benchmark.equals("readseq")) {
641675
for (int t = 0; t < threadNum_; ++t) {
642676
tasks.add(new ReadSequentialTask(
643-
currentTaskId++, randSeed_, reads_, num_));
677+
currentTaskId++, randSeed_, reads_ / threadNum_, num_));
644678
}
645679
} else if (benchmark.equals("readrandom")) {
646680
for (int t = 0; t < threadNum_; ++t) {
647681
tasks.add(new ReadRandomTask(
648-
currentTaskId++, randSeed_, reads_, num_));
682+
currentTaskId++, randSeed_, reads_ / threadNum_, num_));
649683
}
650684
} else if (benchmark.equals("readwhilewriting")) {
651685
WriteTask writeTask = new WriteRandomTask(
@@ -717,12 +751,12 @@ private void printHeader(Options options) {
717751
(int) (valueSize_ * compressionRatio_ + 0.5));
718752
System.out.printf("Entries: %d\n", num_);
719753
System.out.printf("RawSize: %.1f MB (estimated)\n",
720-
((kKeySize + valueSize_) * num_) / 1048576.0);
754+
((double)(kKeySize + valueSize_) * num_) / SizeUnit.MB);
721755
System.out.printf("FileSize: %.1f MB (estimated)\n",
722-
(((kKeySize + valueSize_ * compressionRatio_) * num_)
723-
/ 1048576.0));
756+
(((kKeySize + valueSize_ * compressionRatio_) * num_) / SizeUnit.MB));
724757
System.out.format("Memtable Factory: %s%n", options.memTableFactoryName());
725758
System.out.format("Prefix: %d bytes%n", prefixSize_);
759+
System.out.format("Compression: %s%n", compressionType_);
726760
printWarnings();
727761
System.out.printf("------------------------------------------------\n");
728762
}
@@ -769,7 +803,7 @@ private void stop(
769803

770804
System.out.printf(
771805
"%-16s : %11.5f micros/op; %6.1f MB/s; %d / %d task(s) finished.\n",
772-
benchmark, elapsedSeconds * 1e6 / stats.done_,
806+
benchmark, (double) elapsedSeconds / stats.done_ * 1e6,
773807
(stats.bytes_ / 1048576.0) / elapsedSeconds,
774808
taskFinishedCount, concurrentThreads);
775809
}
@@ -932,7 +966,7 @@ private enum Flag {
932966
return Integer.parseInt(value);
933967
}
934968
},
935-
write_buffer_size(4 << 20,
969+
write_buffer_size(4 * SizeUnit.MB,
936970
"Number of bytes to buffer in memtable before compacting\n" +
937971
"\t(initialized to default value by 'main'.)") {
938972
@Override public Object parseValue(String value) {
@@ -1275,11 +1309,17 @@ private enum Flag {
12751309
return Boolean.parseBoolean(value);
12761310
}
12771311
},
1278-
delete_obsolete_files_period_micros(0L,"Option to delete\n" +
1312+
delete_obsolete_files_period_micros(0,"Option to delete\n" +
12791313
"\tobsolete files periodically. 0 means that obsolete files are\n" +
12801314
"\tdeleted after every compaction run.") {
12811315
@Override public Object parseValue(String value) {
1282-
return Long.parseLong(value);
1316+
return Integer.parseInt(value);
1317+
}
1318+
},
1319+
compression_type("snappy",
1320+
"Algorithm used to compress the database.") {
1321+
@Override public Object parseValue(String value) {
1322+
return value;
12831323
}
12841324
},
12851325
compression_level(-1,
@@ -1512,7 +1552,7 @@ void setFinished(boolean flag) {
15121552
final long cacheSize_;
15131553
final boolean useExisting_;
15141554
final String databaseDir_;
1515-
final double compressionRatio_;
1555+
double compressionRatio_;
15161556
RandomGenerator gen_;
15171557
long startTime_;
15181558

@@ -1532,4 +1572,6 @@ void setFinished(boolean flag) {
15321572
// as the scope of a static member equals to the scope of the problem,
15331573
// we let its c++ pointer to be disposed in its finalizer.
15341574
static Options defaultOptions_ = new Options();
1575+
String compressionType_;
1576+
CompressionType compression_;
15351577
}

java/org/rocksdb/test/ReadOptionsTest.java

-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ public static void main(String[] args) {
2727
assert(opt.fillCache() == boolValue);
2828
}
2929

30-
{ // PrefixSeek test
31-
boolean boolValue = rand.nextBoolean();
32-
opt.setPrefixSeek(boolValue);
33-
assert(opt.prefixSeek() == boolValue);
34-
}
35-
3630
{ // Tailing test
3731
boolean boolValue = rand.nextBoolean();
3832
opt.setTailing(boolValue);

java/rocksjni/options.cc

-21
Original file line numberDiff line numberDiff line change
@@ -1785,27 +1785,6 @@ void Java_org_rocksdb_ReadOptions_setFillCache(
17851785
static_cast<bool>(jfill_cache);
17861786
}
17871787

1788-
/*
1789-
* Class: org_rocksdb_ReadOptions
1790-
* Method: prefixSeek
1791-
* Signature: (J)Z
1792-
*/
1793-
jboolean Java_org_rocksdb_ReadOptions_prefixSeek(
1794-
JNIEnv* env, jobject jobj, jlong jhandle) {
1795-
return reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->prefix_seek;
1796-
}
1797-
1798-
/*
1799-
* Class: org_rocksdb_ReadOptions
1800-
* Method: setPrefixSeek
1801-
* Signature: (JZ)V
1802-
*/
1803-
void Java_org_rocksdb_ReadOptions_setPrefixSeek(
1804-
JNIEnv* env, jobject jobj, jlong jhandle, jboolean jprefix_seek) {
1805-
reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->prefix_seek =
1806-
static_cast<bool>(jprefix_seek);
1807-
}
1808-
18091788
/*
18101789
* Class: org_rocksdb_ReadOptions
18111790
* Method: tailing

java/rocksjni/write_batch.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ jbyteArray Java_org_rocksdb_WriteBatchTest_getContents(
212212
rocksdb::Status s =
213213
rocksdb::WriteBatchInternal::InsertInto(b, &cf_mems_default);
214214
int count = 0;
215-
rocksdb::Iterator* iter = mem->NewIterator();
215+
rocksdb::Iterator* iter = mem->NewIterator(rocksdb::ReadOptions());
216216
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
217217
rocksdb::ParsedInternalKey ikey;
218218
memset(reinterpret_cast<void*>(&ikey), 0, sizeof(ikey));

0 commit comments

Comments
 (0)