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_) {
case "snappy":
System.loadLibrary("snappy"); System.loadLibrary("snappy");
} else if (compressionType_.equals("zlib")) { break;
case "zlib":
System.loadLibrary("z"); System.loadLibrary("z");
} else if (compressionType_.equals("bzip2")) { break;
case "bzip2":
System.loadLibrary("bzip2"); System.loadLibrary("bzip2");
} else if (compressionType_.equals("lz4")) { break;
case "lz4":
System.loadLibrary("lz4"); System.loadLibrary("lz4");
} else if (compressionType_.equals("lz4hc")) { break;
case "lz4hc":
System.loadLibrary("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_) {
case "skip_list":
options.setMemTableConfig(new SkipListMemTableConfig()); options.setMemTableConfig(new SkipListMemTableConfig());
} else if (memtable_.equals("vector")) { break;
case "vector":
options.setMemTableConfig(new VectorMemTableConfig()); options.setMemTableConfig(new VectorMemTableConfig());
} else if (memtable_.equals("hash_linkedlist")) { break;
case "hash_linkedlist":
options.setMemTableConfig( options.setMemTableConfig(
new HashLinkedListMemTableConfig() new HashLinkedListMemTableConfig()
.setBucketCount(hashBucketCount_)); .setBucketCount(hashBucketCount_));
options.useFixedLengthPrefixExtractor(prefixSize_); options.useFixedLengthPrefixExtractor(prefixSize_);
} else if (memtable_.equals("hash_skiplist") || break;
memtable_.equals("prefix_hash")) { case "hash_skiplist":
case "prefix_hash":
options.setMemTableConfig( options.setMemTableConfig(
new HashSkipListMemTableConfig() new HashSkipListMemTableConfig()
.setBucketCount(hashBucketCount_)); .setBucketCount(hashBucketCount_));
options.useFixedLengthPrefixExtractor(prefixSize_); options.useFixedLengthPrefixExtractor(prefixSize_);
} else { break;
default:
System.err.format( System.err.format(
"unable to detect the specified memtable, " + "unable to detect the specified memtable, " +
"use the default memtable factory %s%n", "use the default memtable factory %s%n",
options.memTableFactoryName()); options.memTableFactoryName());
break;
} }
if (usePlainTable_) { if (usePlainTable_) {
options.setTableFormatConfig( options.setTableFormatConfig(
@ -645,34 +657,42 @@ public class DbBenchmark {
int currentTaskId = 0; int currentTaskId = 0;
boolean known = true; boolean known = true;
if (benchmark.equals("fillseq")) { switch (benchmark) {
case "fillseq":
tasks.add(new WriteSequentialTask( tasks.add(new WriteSequentialTask(
currentTaskId++, randSeed_, num_, num_, writeOpt, 1)); currentTaskId++, randSeed_, num_, num_, writeOpt, 1));
} else if (benchmark.equals("fillbatch")) { break;
case "fillbatch":
tasks.add(new WriteRandomTask( tasks.add(new WriteRandomTask(
currentTaskId++, randSeed_, num_ / 1000, num_, writeOpt, 1000)); currentTaskId++, randSeed_, num_ / 1000, num_, writeOpt, 1000));
} else if (benchmark.equals("fillrandom")) { break;
case "fillrandom":
tasks.add(new WriteRandomTask( tasks.add(new WriteRandomTask(
currentTaskId++, randSeed_, num_, num_, writeOpt, 1)); currentTaskId++, randSeed_, num_, num_, writeOpt, 1));
} else if (benchmark.equals("filluniquerandom")) { break;
case "filluniquerandom":
tasks.add(new WriteUniqueRandomTask( tasks.add(new WriteUniqueRandomTask(
currentTaskId++, randSeed_, num_, num_, writeOpt, 1)); currentTaskId++, randSeed_, num_, num_, writeOpt, 1));
} else if (benchmark.equals("fillsync")) { break;
case "fillsync":
writeOpt.setSync(true); writeOpt.setSync(true);
tasks.add(new WriteRandomTask( tasks.add(new WriteRandomTask(
currentTaskId++, randSeed_, num_ / 1000, num_ / 1000, currentTaskId++, randSeed_, num_ / 1000, num_ / 1000,
writeOpt, 1)); writeOpt, 1));
} else if (benchmark.equals("readseq")) { break;
case "readseq":
for (int t = 0; t < threadNum_; ++t) { for (int t = 0; t < threadNum_; ++t) {
tasks.add(new ReadSequentialTask( tasks.add(new ReadSequentialTask(
currentTaskId++, randSeed_, reads_ / threadNum_, num_)); currentTaskId++, randSeed_, reads_ / threadNum_, num_));
} }
} else if (benchmark.equals("readrandom")) { break;
case "readrandom":
for (int t = 0; t < threadNum_; ++t) { for (int t = 0; t < threadNum_; ++t) {
tasks.add(new ReadRandomTask( tasks.add(new ReadRandomTask(
currentTaskId++, randSeed_, reads_ / threadNum_, num_)); currentTaskId++, randSeed_, reads_ / threadNum_, num_));
} }
} else if (benchmark.equals("readwhilewriting")) { break;
case "readwhilewriting":
WriteTask writeTask = new WriteRandomTask( WriteTask writeTask = new WriteRandomTask(
-1, randSeed_, Long.MAX_VALUE, num_, writeOpt, 1, writesPerSeconds_); -1, randSeed_, Long.MAX_VALUE, num_, writeOpt, 1, writesPerSeconds_);
writeTask.stats_.setExcludeFromMerge(); writeTask.stats_.setExcludeFromMerge();
@ -681,17 +701,21 @@ public class DbBenchmark {
tasks.add(new ReadRandomTask( tasks.add(new ReadRandomTask(
currentTaskId++, randSeed_, reads_ / threadNum_, num_)); currentTaskId++, randSeed_, reads_ / threadNum_, num_));
} }
} else if (benchmark.equals("readhot")) { break;
case "readhot":
for (int t = 0; t < threadNum_; ++t) { for (int t = 0; t < threadNum_; ++t) {
tasks.add(new ReadRandomTask( tasks.add(new ReadRandomTask(
currentTaskId++, randSeed_, reads_ / threadNum_, num_ / 100)); currentTaskId++, randSeed_, reads_ / threadNum_, num_ / 100));
} }
} else if (benchmark.equals("delete")) { break;
case "delete":
destroyDb(); destroyDb();
open(options); open(options);
} else { break;
default:
known = false; known = false;
System.err.println("Unknown benchmark: " + benchmark); 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();
}
} }
} }