RocksJava - FindBugs issues

Addressed some FindBugs issues.
This commit is contained in:
fyrz 2014-11-22 20:59:00 +01:00
parent 9a632b4a92
commit b036804ac1
7 changed files with 120 additions and 81 deletions

View File

@ -44,6 +44,9 @@ public class RocksDBColumnFamilySample {
db.close(); db.close();
db = null; db = null;
} }
if (options != null) {
options.dispose();
}
} }
// open DB with two column families // open DB with two column families

View File

@ -119,7 +119,7 @@ public class RocksDBSample {
byte[] value = db.get("hello".getBytes()); byte[] value = db.get("hello".getBytes());
assert("world".equals(new String(value))); assert("world".equals(new String(value)));
String str = db.getProperty("rocksdb.stats"); String str = db.getProperty("rocksdb.stats");
assert(str != null && str != ""); assert(str != null && !str.equals(""));
} catch (RocksDBException e) { } catch (RocksDBException e) {
System.out.format("[ERROR] caught the unexpceted exception -- %s\n", e); System.out.format("[ERROR] caught the unexpceted exception -- %s\n", e);
assert(db == null); assert(db == null);

View File

@ -40,5 +40,5 @@ public class ColumnFamilyHandle extends RocksObject {
private native void disposeInternal(long handle); private native void disposeInternal(long handle);
private RocksDB rocksDB_; private final RocksDB rocksDB_;
} }

View File

@ -162,5 +162,5 @@ public class RocksIterator extends RocksObject {
private native void seek0(long handle, byte[] target, int targetLen); private native void seek0(long handle, byte[] target, int targetLen);
private native void status0(long handle); private native void status0(long handle);
RocksDB rocksDB_; final RocksDB rocksDB_;
} }

View File

@ -459,16 +459,22 @@ public class DbBenchmark {
compressionType_ = (String) flags.get(Flag.compression_type); compressionType_ = (String) flags.get(Flag.compression_type);
compression_ = CompressionType.NONE; compression_ = CompressionType.NONE;
try { try {
if (compressionType_.equals("snappy")) { switch (compressionType_) {
System.loadLibrary("snappy"); case "snappy":
} else if (compressionType_.equals("zlib")) { System.loadLibrary("snappy");
System.loadLibrary("z"); break;
} else if (compressionType_.equals("bzip2")) { case "zlib":
System.loadLibrary("bzip2"); System.loadLibrary("z");
} else if (compressionType_.equals("lz4")) { break;
System.loadLibrary("lz4"); case "bzip2":
} else if (compressionType_.equals("lz4hc")) { System.loadLibrary("bzip2");
System.loadLibrary("lz4hc"); break;
case "lz4":
System.loadLibrary("lz4");
break;
case "lz4hc":
System.loadLibrary("lz4hc");
break;
} }
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
System.err.format("Unable to load %s library:%s%n" + System.err.format("Unable to load %s library:%s%n" +
@ -495,26 +501,32 @@ public class DbBenchmark {
} else { } else {
options.setCreateIfMissing(false); options.setCreateIfMissing(false);
} }
if (memtable_.equals("skip_list")) { switch (memtable_) {
options.setMemTableConfig(new SkipListMemTableConfig()); case "skip_list":
} else if (memtable_.equals("vector")) { options.setMemTableConfig(new SkipListMemTableConfig());
options.setMemTableConfig(new VectorMemTableConfig()); break;
} else if (memtable_.equals("hash_linkedlist")) { case "vector":
options.setMemTableConfig( options.setMemTableConfig(new VectorMemTableConfig());
new HashLinkedListMemTableConfig() break;
.setBucketCount(hashBucketCount_)); case "hash_linkedlist":
options.useFixedLengthPrefixExtractor(prefixSize_); options.setMemTableConfig(
} else if (memtable_.equals("hash_skiplist") || new HashLinkedListMemTableConfig()
memtable_.equals("prefix_hash")) { .setBucketCount(hashBucketCount_));
options.setMemTableConfig( options.useFixedLengthPrefixExtractor(prefixSize_);
new HashSkipListMemTableConfig() break;
.setBucketCount(hashBucketCount_)); case "hash_skiplist":
options.useFixedLengthPrefixExtractor(prefixSize_); case "prefix_hash":
} else { options.setMemTableConfig(
System.err.format( new HashSkipListMemTableConfig()
"unable to detect the specified memtable, " + .setBucketCount(hashBucketCount_));
"use the default memtable factory %s%n", options.useFixedLengthPrefixExtractor(prefixSize_);
options.memTableFactoryName()); break;
default:
System.err.format(
"unable to detect the specified memtable, " +
"use the default memtable factory %s%n",
options.memTableFactoryName());
break;
} }
if (usePlainTable_) { if (usePlainTable_) {
options.setTableFormatConfig( options.setTableFormatConfig(
@ -645,53 +657,65 @@ public class DbBenchmark {
int currentTaskId = 0; int currentTaskId = 0;
boolean known = true; boolean known = true;
if (benchmark.equals("fillseq")) { switch (benchmark) {
tasks.add(new WriteSequentialTask( case "fillseq":
currentTaskId++, randSeed_, num_, num_, writeOpt, 1)); tasks.add(new WriteSequentialTask(
} else if (benchmark.equals("fillbatch")) { currentTaskId++, randSeed_, num_, num_, writeOpt, 1));
tasks.add(new WriteRandomTask( break;
currentTaskId++, randSeed_, num_ / 1000, num_, writeOpt, 1000)); case "fillbatch":
} else if (benchmark.equals("fillrandom")) { tasks.add(new WriteRandomTask(
tasks.add(new WriteRandomTask( currentTaskId++, randSeed_, num_ / 1000, num_, writeOpt, 1000));
currentTaskId++, randSeed_, num_, num_, writeOpt, 1)); break;
} else if (benchmark.equals("filluniquerandom")) { case "fillrandom":
tasks.add(new WriteUniqueRandomTask( tasks.add(new WriteRandomTask(
currentTaskId++, randSeed_, num_, num_, writeOpt, 1)); currentTaskId++, randSeed_, num_, num_, writeOpt, 1));
} else if (benchmark.equals("fillsync")) { break;
writeOpt.setSync(true); case "filluniquerandom":
tasks.add(new WriteRandomTask( tasks.add(new WriteUniqueRandomTask(
currentTaskId++, randSeed_, num_ / 1000, num_ / 1000, currentTaskId++, randSeed_, num_, num_, writeOpt, 1));
writeOpt, 1)); break;
} else if (benchmark.equals("readseq")) { case "fillsync":
for (int t = 0; t < threadNum_; ++t) { writeOpt.setSync(true);
tasks.add(new ReadSequentialTask( tasks.add(new WriteRandomTask(
currentTaskId++, randSeed_, reads_ / threadNum_, num_)); currentTaskId++, randSeed_, num_ / 1000, num_ / 1000,
} writeOpt, 1));
} else if (benchmark.equals("readrandom")) { break;
for (int t = 0; t < threadNum_; ++t) { case "readseq":
tasks.add(new ReadRandomTask( for (int t = 0; t < threadNum_; ++t) {
currentTaskId++, randSeed_, reads_ / threadNum_, num_)); tasks.add(new ReadSequentialTask(
} currentTaskId++, randSeed_, reads_ / threadNum_, num_));
} else if (benchmark.equals("readwhilewriting")) { }
WriteTask writeTask = new WriteRandomTask( break;
-1, randSeed_, Long.MAX_VALUE, num_, writeOpt, 1, writesPerSeconds_); case "readrandom":
writeTask.stats_.setExcludeFromMerge(); for (int t = 0; t < threadNum_; ++t) {
bgTasks.add(writeTask); tasks.add(new ReadRandomTask(
for (int t = 0; t < threadNum_; ++t) { currentTaskId++, randSeed_, reads_ / threadNum_, num_));
tasks.add(new ReadRandomTask( }
currentTaskId++, randSeed_, reads_ / threadNum_, num_)); break;
} case "readwhilewriting":
} else if (benchmark.equals("readhot")) { WriteTask writeTask = new WriteRandomTask(
for (int t = 0; t < threadNum_; ++t) { -1, randSeed_, Long.MAX_VALUE, num_, writeOpt, 1, writesPerSeconds_);
tasks.add(new ReadRandomTask( writeTask.stats_.setExcludeFromMerge();
currentTaskId++, randSeed_, reads_ / threadNum_, num_ / 100)); bgTasks.add(writeTask);
} for (int t = 0; t < threadNum_; ++t) {
} else if (benchmark.equals("delete")) { tasks.add(new ReadRandomTask(
destroyDb(); currentTaskId++, randSeed_, reads_ / threadNum_, num_));
open(options); }
} else { break;
known = false; case "readhot":
System.err.println("Unknown benchmark: " + benchmark); for (int t = 0; t < threadNum_; ++t) {
tasks.add(new ReadRandomTask(
currentTaskId++, randSeed_, reads_ / threadNum_, num_ / 100));
}
break;
case "delete":
destroyDb();
open(options);
break;
default:
known = false;
System.err.println("Unknown benchmark: " + benchmark);
break;
} }
if (known) { if (known) {
ExecutorService executor = Executors.newCachedThreadPool(); ExecutorService executor = Executors.newCachedThreadPool();
@ -800,7 +824,7 @@ public class DbBenchmark {
System.out.printf( System.out.printf(
"%-16s : %11.5f micros/op; %6.1f MB/s;%s %d / %d task(s) finished.\n", "%-16s : %11.5f micros/op; %6.1f MB/s;%s %d / %d task(s) finished.\n",
benchmark, (double) elapsedSeconds / stats.done_ * 1e6, benchmark, elapsedSeconds / stats.done_ * 1e6,
(stats.bytes_ / 1048576.0) / elapsedSeconds, extra, (stats.bytes_ / 1048576.0) / elapsedSeconds, extra,
taskFinishedCount, concurrentThreads); taskFinishedCount, concurrentThreads);
} }

View File

@ -171,6 +171,9 @@ public class ColumnFamilyTest {
if (db != null) { if (db != null) {
db.close(); db.close();
} }
if (options != null) {
options.dispose();
}
} }
} }

View File

@ -57,6 +57,9 @@ public class InfoLogLevelTest {
if (db != null) { if (db != null) {
db.close(); db.close();
} }
if (options != null) {
options.dispose();
}
} }
} }
@ -84,6 +87,12 @@ public class InfoLogLevelTest {
if (db != null) { if (db != null) {
db.close(); db.close();
} }
if (options != null) {
options.dispose();
}
if (dbOptions != null) {
dbOptions.dispose();
}
} }
} }