From 05fffd431fb08f7be9ccc652f8491898b064d8ee Mon Sep 17 00:00:00 2001
From: Dain Sundstrom
Date: Fri, 31 Oct 2014 16:39:32 -0700
Subject: [PATCH] Add code style checker and update to style
---
.../org/iq80/leveldb/CompressionType.java | 3 +-
.../src/main/java/org/iq80/leveldb/DB.java | 47 ++--
.../java/org/iq80/leveldb/DBComparator.java | 12 +-
.../java/org/iq80/leveldb/DBException.java | 16 +-
.../main/java/org/iq80/leveldb/DBFactory.java | 14 +-
.../java/org/iq80/leveldb/DBIterator.java | 6 +-
.../main/java/org/iq80/leveldb/Logger.java | 5 +-
.../main/java/org/iq80/leveldb/Options.java | 36 ++-
.../src/main/java/org/iq80/leveldb/Range.java | 18 +-
.../java/org/iq80/leveldb/ReadOptions.java | 12 +-
.../main/java/org/iq80/leveldb/Snapshot.java | 5 +-
.../java/org/iq80/leveldb/WriteBatch.java | 6 +-
.../java/org/iq80/leveldb/WriteOptions.java | 8 +-
.../iq80/leveldb/benchmark/DbBenchmark.java | 248 +++++++++---------
.../org/iq80/leveldb/impl/Compaction.java | 9 +-
.../org/iq80/leveldb/impl/DbConstants.java | 5 +-
.../java/org/iq80/leveldb/impl/DbImpl.java | 141 ++++++----
.../leveldb/impl/FileChannelLogWriter.java | 3 +-
.../org/iq80/leveldb/impl/FileMetaData.java | 2 +-
.../java/org/iq80/leveldb/impl/Filename.java | 7 +-
.../org/iq80/leveldb/impl/InternalEntry.java | 5 +-
.../org/iq80/leveldb/impl/InternalKey.java | 18 +-
.../leveldb/impl/InternalKeyComparator.java | 7 +-
.../leveldb/impl/InternalUserComparator.java | 12 +-
.../org/iq80/leveldb/impl/Iq80DBFactory.java | 58 ++--
.../java/org/iq80/leveldb/impl/Level.java | 7 +-
.../java/org/iq80/leveldb/impl/Level0.java | 9 +-
.../org/iq80/leveldb/impl/LogChunkType.java | 4 +-
.../org/iq80/leveldb/impl/LogConstants.java | 5 +-
.../org/iq80/leveldb/impl/LogMonitor.java | 1 +
.../org/iq80/leveldb/impl/LogMonitors.java | 6 +-
.../java/org/iq80/leveldb/impl/LogReader.java | 2 +-
.../main/java/org/iq80/leveldb/impl/Logs.java | 7 +-
.../org/iq80/leveldb/impl/LookupResult.java | 3 +-
.../org/iq80/leveldb/impl/MMapLogWriter.java | 5 +-
.../java/org/iq80/leveldb/impl/MemTable.java | 10 +-
.../java/org/iq80/leveldb/impl/ReadStats.java | 3 +-
.../iq80/leveldb/impl/SeekingIterable.java | 3 +-
.../iq80/leveldb/impl/SeekingIterator.java | 3 +-
.../leveldb/impl/SeekingIteratorAdapter.java | 9 +-
.../org/iq80/leveldb/impl/SequenceNumber.java | 4 +
.../org/iq80/leveldb/impl/SnapshotImpl.java | 36 ++-
.../leveldb/impl/SnapshotSeekingIterator.java | 7 +-
.../org/iq80/leveldb/impl/TableCache.java | 26 +-
.../java/org/iq80/leveldb/impl/ValueType.java | 3 +-
.../java/org/iq80/leveldb/impl/Version.java | 43 +--
.../org/iq80/leveldb/impl/VersionEdit.java | 4 +-
.../org/iq80/leveldb/impl/VersionEditTag.java | 9 +-
.../org/iq80/leveldb/impl/VersionSet.java | 175 ++++++------
.../org/iq80/leveldb/impl/WriteBatchImpl.java | 4 +-
.../java/org/iq80/leveldb/table/Block.java | 4 +-
.../org/iq80/leveldb/table/BlockEntry.java | 5 +-
.../org/iq80/leveldb/table/BlockHandle.java | 6 +-
.../org/iq80/leveldb/table/BlockIterator.java | 7 +-
.../org/iq80/leveldb/table/BlockTrailer.java | 4 +-
.../leveldb/table/BytewiseComparator.java | 9 +-
.../leveldb/table/CustomUserComparator.java | 12 +-
.../iq80/leveldb/table/FileChannelTable.java | 19 +-
.../java/org/iq80/leveldb/table/Footer.java | 7 +-
.../org/iq80/leveldb/table/MMapTable.java | 15 +-
.../java/org/iq80/leveldb/table/Table.java | 16 +-
.../org/iq80/leveldb/table/TableBuilder.java | 2 +-
.../iq80/leveldb/table/UserComparator.java | 3 +-
.../leveldb/util/AbstractSeekingIterator.java | 5 +-
.../iq80/leveldb/util/BasicSliceOutput.java | 3 +-
.../iq80/leveldb/util/ByteBufferSupport.java | 109 ++++----
.../org/iq80/leveldb/util/Closeables.java | 4 +-
.../org/iq80/leveldb/util/DbIterator.java | 9 +-
.../iq80/leveldb/util/DynamicSliceOutput.java | 3 +-
.../java/org/iq80/leveldb/util/FileUtils.java | 6 +-
.../java/org/iq80/leveldb/util/Finalizer.java | 27 +-
.../java/org/iq80/leveldb/util/IntVector.java | 4 +-
.../iq80/leveldb/util/InternalIterator.java | 4 +-
.../leveldb/util/InternalTableIterator.java | 4 +-
.../org/iq80/leveldb/util/Level0Iterator.java | 13 +-
.../org/iq80/leveldb/util/LevelIterator.java | 4 +-
.../iq80/leveldb/util/MergingIterator.java | 12 +-
.../org/iq80/leveldb/util/PureJavaCrc32C.java | 29 +-
.../java/org/iq80/leveldb/util/Slice.java | 24 +-
.../iq80/leveldb/util/SliceComparator.java | 3 +-
.../org/iq80/leveldb/util/SliceInput.java | 4 +-
.../org/iq80/leveldb/util/SliceOutput.java | 89 +++----
.../java/org/iq80/leveldb/util/Slices.java | 3 -
.../java/org/iq80/leveldb/util/Snappy.java | 157 +++++++----
.../org/iq80/leveldb/util/TableIterator.java | 3 +-
.../java/org/iq80/leveldb/impl/ApiTest.java | 59 +++--
.../org/iq80/leveldb/impl/DbImplTest.java | 26 +-
.../java/org/iq80/leveldb/impl/LogTest.java | 3 +-
.../iq80/leveldb/impl/NativeInteropTest.java | 67 +++--
.../impl/TestFileChannelLogWriter.java | 5 +-
.../iq80/leveldb/impl/TestMMapLogWriter.java | 6 +-
.../org/iq80/leveldb/table/BlockHelper.java | 6 +-
.../org/iq80/leveldb/table/BlockTest.java | 4 +-
.../leveldb/table/FileChannelTableTest.java | 7 +-
.../org/iq80/leveldb/table/MMapTableTest.java | 7 +-
.../org/iq80/leveldb/table/TableTest.java | 10 +-
.../iq80/leveldb/util/PureJavaCrc32CTest.java | 17 +-
.../leveldb/util/SliceComparatorTest.java | 9 +-
pom.xml | 26 ++
src/checkstyle/checks.xml | 117 +++++++++
100 files changed, 1253 insertions(+), 835 deletions(-)
create mode 100644 src/checkstyle/checks.xml
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/CompressionType.java b/leveldb-api/src/main/java/org/iq80/leveldb/CompressionType.java
index 84b026bb..f17733bd 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/CompressionType.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/CompressionType.java
@@ -22,7 +22,8 @@ public enum CompressionType
NONE(0x00),
SNAPPY(0x01);
- public static CompressionType getCompressionTypeByPersistentId(int persistentId) {
+ public static CompressionType getCompressionTypeByPersistentId(int persistentId)
+ {
for (CompressionType compressionType : CompressionType.values()) {
if (compressionType.persistentId == persistentId) {
return compressionType;
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/DB.java b/leveldb-api/src/main/java/org/iq80/leveldb/DB.java
index 4226f87e..72b6aa65 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/DB.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/DB.java
@@ -23,48 +23,63 @@
/**
* @author Hiram Chirino
*/
-public interface DB extends Iterable>, Closeable {
+public interface DB
+ extends Iterable>, Closeable
+{
+ public byte[] get(byte[] key)
+ throws DBException;
- public byte[] get(byte[] key) throws DBException;
- public byte[] get(byte[] key, ReadOptions options) throws DBException;
+ public byte[] get(byte[] key, ReadOptions options)
+ throws DBException;
public DBIterator iterator();
+
public DBIterator iterator(ReadOptions options);
- public void put(byte[] key, byte[] value) throws DBException;
- public void delete(byte[] key) throws DBException;
- public void write(WriteBatch updates) throws DBException;
+ public void put(byte[] key, byte[] value)
+ throws DBException;
+
+ public void delete(byte[] key)
+ throws DBException;
+
+ public void write(WriteBatch updates)
+ throws DBException;
public WriteBatch createWriteBatch();
/**
* @return null if options.isSnapshot()==false otherwise returns a snapshot
- * of the DB after this operation.
+ * of the DB after this operation.
*/
- public Snapshot put(byte[] key, byte[] value, WriteOptions options) throws DBException;
+ public Snapshot put(byte[] key, byte[] value, WriteOptions options)
+ throws DBException;
/**
* @return null if options.isSnapshot()==false otherwise returns a snapshot
- * of the DB after this operation.
+ * of the DB after this operation.
*/
- public Snapshot delete(byte[] key, WriteOptions options) throws DBException;
+ public Snapshot delete(byte[] key, WriteOptions options)
+ throws DBException;
/**
* @return null if options.isSnapshot()==false otherwise returns a snapshot
- * of the DB after this operation.
+ * of the DB after this operation.
*/
- public Snapshot write(WriteBatch updates, WriteOptions options) throws DBException;
+ public Snapshot write(WriteBatch updates, WriteOptions options)
+ throws DBException;
public Snapshot getSnapshot();
- public long[] getApproximateSizes(Range ... ranges);
+ public long[] getApproximateSizes(Range... ranges);
+
public String getProperty(String name);
/**
* Suspends any background compaction threads. This methods
* returns once the background compactions are suspended.
*/
- public void suspendCompactions() throws InterruptedException;
+ public void suspendCompactions()
+ throws InterruptedException;
/**
* Resumes the background compaction threads.
@@ -76,7 +91,7 @@ public interface DB extends Iterable>, Closeable {
*
* @param begin if null then compaction start from the first key
* @param end if null then compaction ends at the last key
- * @throws DBException
*/
- public void compactRange(byte[] begin, byte[] end) throws DBException;
+ public void compactRange(byte[] begin, byte[] end)
+ throws DBException;
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/DBComparator.java b/leveldb-api/src/main/java/org/iq80/leveldb/DBComparator.java
index 6a2bb576..e0fb9a03 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/DBComparator.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/DBComparator.java
@@ -22,26 +22,20 @@
/**
* @author Hiram Chirino
*/
-public interface DBComparator extends Comparator{
-
+public interface DBComparator
+ extends Comparator
+{
public String name();
/**
* If start < limit
, returns a short key in [start,limit).
* Simple comparator implementations should return start unchanged,
- *
- * @param start
- * @param limit
- * @return
*/
byte[] findShortestSeparator(byte[] start, byte[] limit);
/**
* returns a 'short key' where the 'short key' >= key.
* Simple comparator implementations should return key unchanged,
- *
- * @param key
*/
byte[] findShortSuccessor(byte[] key);
-
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/DBException.java b/leveldb-api/src/main/java/org/iq80/leveldb/DBException.java
index 9d67c188..11e7e60b 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/DBException.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/DBException.java
@@ -20,19 +20,25 @@
/**
* @author Hiram Chirino
*/
-public class DBException extends RuntimeException {
- public DBException() {
+public class DBException
+ extends RuntimeException
+{
+ public DBException()
+ {
}
- public DBException(String s) {
+ public DBException(String s)
+ {
super(s);
}
- public DBException(String s, Throwable throwable) {
+ public DBException(String s, Throwable throwable)
+ {
super(s, throwable);
}
- public DBException(Throwable throwable) {
+ public DBException(Throwable throwable)
+ {
super(throwable);
}
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/DBFactory.java b/leveldb-api/src/main/java/org/iq80/leveldb/DBFactory.java
index 70c31646..bdc08cdf 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/DBFactory.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/DBFactory.java
@@ -23,12 +23,14 @@
/**
* @author Hiram Chirino
*/
-public interface DBFactory {
+public interface DBFactory
+{
+ public DB open(File path, Options options)
+ throws IOException;
- public DB open(File path, Options options) throws IOException;
-
- public void destroy(File path, Options options) throws IOException;
-
- public void repair(File path, Options options) throws IOException;
+ public void destroy(File path, Options options)
+ throws IOException;
+ public void repair(File path, Options options)
+ throws IOException;
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/DBIterator.java b/leveldb-api/src/main/java/org/iq80/leveldb/DBIterator.java
index 41e73399..4af87716 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/DBIterator.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/DBIterator.java
@@ -24,8 +24,9 @@
/**
* @author Hiram Chirino
*/
-public interface DBIterator extends Iterator>, Closeable {
-
+public interface DBIterator
+ extends Iterator>, Closeable
+{
/**
* Repositions the iterator so the key of the next BlockElement
* returned greater than or equal to the specified targetKey.
@@ -61,5 +62,4 @@ public interface DBIterator extends Iterator>, Closeab
* Repositions the iterator so it is at the end of of the Database.
*/
public void seekToLast();
-
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/Logger.java b/leveldb-api/src/main/java/org/iq80/leveldb/Logger.java
index 22cf9e6c..9073de8a 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/Logger.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/Logger.java
@@ -20,8 +20,7 @@
/**
* @author Hiram Chirino
*/
-public interface Logger {
-
+public interface Logger
+{
public void log(String message);
-
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/Options.java b/leveldb-api/src/main/java/org/iq80/leveldb/Options.java
index f05d8361..4aa1f6c4 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/Options.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/Options.java
@@ -17,8 +17,8 @@
*/
package org.iq80.leveldb;
-public class Options {
-
+public class Options
+{
private boolean createIfMissing = true;
private boolean errorIfExists;
private int writeBufferSize = 4 << 20;
@@ -34,9 +34,10 @@ public class Options {
private Logger logger = null;
private long cacheSize;
- static void checkArgNotNull(Object value, String name) {
- if(value==null) {
- throw new IllegalArgumentException("The "+name+" argument cannot be null");
+ static void checkArgNotNull(Object value, String name)
+ {
+ if (value == null) {
+ throw new IllegalArgumentException("The " + name + " argument cannot be null");
}
}
@@ -129,39 +130,46 @@ public Options verifyChecksums(boolean verifyChecksums)
return this;
}
-
- public long cacheSize() {
+ public long cacheSize()
+ {
return cacheSize;
}
- public Options cacheSize(long cacheSize) {
+ public Options cacheSize(long cacheSize)
+ {
this.cacheSize = cacheSize;
return this;
}
- public DBComparator comparator() {
+ public DBComparator comparator()
+ {
return comparator;
}
- public Options comparator(DBComparator comparator) {
+ public Options comparator(DBComparator comparator)
+ {
this.comparator = comparator;
return this;
}
- public Logger logger() {
+ public Logger logger()
+ {
return logger;
}
- public Options logger(Logger logger) {
+ public Options logger(Logger logger)
+ {
this.logger = logger;
return this;
}
- public boolean paranoidChecks() {
+ public boolean paranoidChecks()
+ {
return paranoidChecks;
}
- public Options paranoidChecks(boolean paranoidChecks) {
+ public Options paranoidChecks(boolean paranoidChecks)
+ {
this.paranoidChecks = paranoidChecks;
return this;
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/Range.java b/leveldb-api/src/main/java/org/iq80/leveldb/Range.java
index 51d54cbb..1b7432bc 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/Range.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/Range.java
@@ -20,24 +20,26 @@
/**
* @author Hiram Chirino
*/
-public class Range {
+public class Range
+{
+ private final byte[] start;
+ private final byte[] limit;
- final private byte[] start;
- final private byte[] limit;
-
- public byte[] limit() {
+ public byte[] limit()
+ {
return limit;
}
- public byte[] start() {
+ public byte[] start()
+ {
return start;
}
- public Range(byte[] start, byte[] limit) {
+ public Range(byte[] start, byte[] limit)
+ {
Options.checkArgNotNull(start, "start");
Options.checkArgNotNull(limit, "limit");
this.limit = limit;
this.start = start;
}
-
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/ReadOptions.java b/leveldb-api/src/main/java/org/iq80/leveldb/ReadOptions.java
index 2e56ca41..12445111 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/ReadOptions.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/ReadOptions.java
@@ -34,20 +34,24 @@ public ReadOptions snapshot(Snapshot snapshot)
return this;
}
- public boolean fillCache() {
+ public boolean fillCache()
+ {
return fillCache;
}
- public ReadOptions fillCache(boolean fillCache) {
+ public ReadOptions fillCache(boolean fillCache)
+ {
this.fillCache = fillCache;
return this;
}
- public boolean verifyChecksums() {
+ public boolean verifyChecksums()
+ {
return verifyChecksums;
}
- public ReadOptions verifyChecksums(boolean verifyChecksums) {
+ public ReadOptions verifyChecksums(boolean verifyChecksums)
+ {
this.verifyChecksums = verifyChecksums;
return this;
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/Snapshot.java b/leveldb-api/src/main/java/org/iq80/leveldb/Snapshot.java
index efdfa6d9..8822c74d 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/Snapshot.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/Snapshot.java
@@ -19,6 +19,7 @@
import java.io.Closeable;
-public interface Snapshot extends Closeable {
-
+public interface Snapshot
+ extends Closeable
+{
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/WriteBatch.java b/leveldb-api/src/main/java/org/iq80/leveldb/WriteBatch.java
index 2d0d7bff..0fa475b1 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/WriteBatch.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/WriteBatch.java
@@ -22,8 +22,10 @@
/**
* @author Hiram Chirino
*/
-public interface WriteBatch extends Closeable {
-
+public interface WriteBatch
+ extends Closeable
+{
public WriteBatch put(byte[] key, byte[] value);
+
public WriteBatch delete(byte[] key);
}
diff --git a/leveldb-api/src/main/java/org/iq80/leveldb/WriteOptions.java b/leveldb-api/src/main/java/org/iq80/leveldb/WriteOptions.java
index 762ebf81..819c334e 100644
--- a/leveldb-api/src/main/java/org/iq80/leveldb/WriteOptions.java
+++ b/leveldb-api/src/main/java/org/iq80/leveldb/WriteOptions.java
@@ -22,7 +22,6 @@ public class WriteOptions
private boolean sync;
private boolean snapshot;
-
public boolean sync()
{
return sync;
@@ -34,13 +33,14 @@ public WriteOptions sync(boolean sync)
return this;
}
- public boolean snapshot() {
+ public boolean snapshot()
+ {
return snapshot;
}
- public WriteOptions snapshot(boolean snapshot) {
+ public WriteOptions snapshot(boolean snapshot)
+ {
this.snapshot = snapshot;
return this;
}
-
}
diff --git a/leveldb-benchmark/src/main/java/org/iq80/leveldb/benchmark/DbBenchmark.java b/leveldb-benchmark/src/main/java/org/iq80/leveldb/benchmark/DbBenchmark.java
index b9d22e9a..1f4ee6f8 100644
--- a/leveldb-benchmark/src/main/java/org/iq80/leveldb/benchmark/DbBenchmark.java
+++ b/leveldb-benchmark/src/main/java/org/iq80/leveldb/benchmark/DbBenchmark.java
@@ -76,41 +76,41 @@ enum DBState
}
// Cache cache_;
- private List benchmarks;
- private DB db_;
- private final int num_;
- private int reads_;
+ private final List benchmarks;
+ private DB db;
+ private final int num;
+ private int reads;
private final int valueSize;
- private int heap_counter_;
- private double last_op_finish_;
- private long bytes_;
- private String message_;
- private String post_message_;
+ private int heapCounter;
+ private double lastOpFinish;
+ private long bytes;
+ private String message;
+ private String postMessage;
// private Histogram hist_;
- private RandomGenerator gen_;
- private final Random rand_;
+ private RandomGenerator generator;
+ private final Random random;
// State kept for progress messages
- int done_;
- int next_report_; // When to report next
+ int done;
+ int nextReport; // When to report next
final DBFactory factory;
- public DbBenchmark(Map flags) throws Exception
+ public DbBenchmark(Map flags)
+ throws Exception
{
ClassLoader cl = DbBenchmark.class.getClassLoader();
factory = (DBFactory) cl.loadClass(System.getProperty("leveldb.factory", "org.iq80.leveldb.impl.Iq80DBFactory")).newInstance();
benchmarks = (List) flags.get(Flag.benchmarks);
- num_ = (Integer) flags.get(Flag.num);
- reads_ = (Integer) (flags.get(Flag.reads) == null ? flags.get(Flag.num) : flags.get(Flag.reads));
+ num = (Integer) flags.get(Flag.num);
+ reads = (Integer) (flags.get(Flag.reads) == null ? flags.get(Flag.num) : flags.get(Flag.reads));
valueSize = (Integer) flags.get(Flag.value_size);
writeBufferSize = (Integer) flags.get(Flag.write_buffer_size);
compressionRatio = (Double) flags.get(Flag.compression_ratio);
useExisting = (Boolean) flags.get(Flag.use_existing_db);
- heap_counter_ = 0;
- bytes_ = 0;
- rand_ = new Random(301);
-
+ heapCounter = 0;
+ bytes = 0;
+ random = new Random(301);
databaseDir = new File((String) flags.get(Flag.db));
@@ -125,7 +125,7 @@ public DbBenchmark(Map flags) throws Exception
destroyDb();
}
- gen_ = new RandomGenerator(compressionRatio);
+ generator = new RandomGenerator(compressionRatio);
}
private void run()
@@ -140,22 +140,22 @@ private void run()
boolean known = true;
if (benchmark.equals("fillseq")) {
- write(new WriteOptions(), SEQUENTIAL, FRESH, num_, valueSize, 1);
+ write(new WriteOptions(), SEQUENTIAL, FRESH, num, valueSize, 1);
}
else if (benchmark.equals("fillbatch")) {
- write(new WriteOptions(), SEQUENTIAL, FRESH, num_, valueSize, 1000);
+ write(new WriteOptions(), SEQUENTIAL, FRESH, num, valueSize, 1000);
}
else if (benchmark.equals("fillrandom")) {
- write(new WriteOptions(), RANDOM, FRESH, num_, valueSize, 1);
+ write(new WriteOptions(), RANDOM, FRESH, num, valueSize, 1);
}
else if (benchmark.equals("overwrite")) {
- write(new WriteOptions(), RANDOM, EXISTING, num_, valueSize, 1);
+ write(new WriteOptions(), RANDOM, EXISTING, num, valueSize, 1);
}
else if (benchmark.equals("fillsync")) {
- write(new WriteOptions().sync(true), RANDOM, FRESH, num_ / 1000, valueSize, 1);
+ write(new WriteOptions().sync(true), RANDOM, FRESH, num / 1000, valueSize, 1);
}
else if (benchmark.equals("fill100K")) {
- write(new WriteOptions(), RANDOM, FRESH, num_ / 1000, 100 * 1000, 1);
+ write(new WriteOptions(), RANDOM, FRESH, num / 1000, 100 * 1000, 1);
}
else if (benchmark.equals("readseq")) {
readSequential();
@@ -170,10 +170,10 @@ else if (benchmark.equals("readhot")) {
readHot();
}
else if (benchmark.equals("readrandomsmall")) {
- int n = reads_;
- reads_ /= 1000;
+ int n = reads;
+ reads /= 1000;
readRandom();
- reads_ = n;
+ reads = n;
}
else if (benchmark.equals("compact")) {
compact();
@@ -185,22 +185,22 @@ else if (benchmark.equals("acquireload")) {
acquireLoad();
}
else if (benchmark.equals("snappycomp")) {
- if( Snappy.available() ) {
+ if (Snappy.available()) {
snappyCompress();
}
}
else if (benchmark.equals("snappyuncomp")) {
- if( Snappy.available() ) {
+ if (Snappy.available()) {
snappyUncompressDirectBuffer();
}
}
else if (benchmark.equals("unsnap-array")) {
- if( Snappy.available() ) {
+ if (Snappy.available()) {
snappyUncompressArray();
}
}
else if (benchmark.equals("unsnap-direct")) {
- if( Snappy.available() ) {
+ if (Snappy.available()) {
snappyUncompressDirectBuffer();
}
}
@@ -218,7 +218,7 @@ else if (benchmark.equals("stats")) {
stop(benchmark);
}
}
- db_.close();
+ db.close();
}
private void printHeader()
@@ -230,11 +230,11 @@ private void printHeader()
System.out.printf("Values: %d bytes each (%d bytes after compression)\n",
valueSize,
(int) (valueSize * compressionRatio + 0.5));
- System.out.printf("Entries: %d\n", num_);
+ System.out.printf("Entries: %d\n", num);
System.out.printf("RawSize: %.1f MB (estimated)\n",
- ((kKeySize + valueSize) * num_) / 1048576.0);
+ ((kKeySize + valueSize) * num) / 1048576.0);
System.out.printf("FileSize: %.1f MB (estimated)\n",
- (((kKeySize + valueSize * compressionRatio) * num_)
+ (((kKeySize + valueSize * compressionRatio) * num)
/ 1048576.0));
printWarnings();
System.out.printf("------------------------------------------------\n");
@@ -242,8 +242,8 @@ private void printHeader()
void printWarnings()
{
- boolean assertsEnabled = false;
- assert assertsEnabled = true; // Intentional side effect!!!
+ boolean assertsEnabled = true;
+ assert assertsEnabled; // Intentional side effect!!!
if (assertsEnabled) {
System.out.printf("WARNING: Assertions are enabled; benchmarks unnecessarily slow\n");
}
@@ -306,18 +306,18 @@ private void open()
if (writeBufferSize != null) {
options.writeBufferSize(writeBufferSize);
}
- db_ = factory.open(databaseDir, options);
+ db = factory.open(databaseDir, options);
}
private void start()
{
startTime = System.nanoTime();
- bytes_ = 0;
- message_ = null;
- last_op_finish_ = startTime;
+ bytes = 0;
+ message = null;
+ lastOpFinish = startTime;
// hist.clear();
- done_ = 0;
- next_report_ = 100;
+ done = 0;
+ nextReport = 100;
}
private void stop(String benchmark)
@@ -327,68 +327,68 @@ private void stop(String benchmark)
// Pretend at least one op was done in case we are running a benchmark
// that does nto call FinishedSingleOp().
- if (done_ < 1) {
- done_ = 1;
+ if (done < 1) {
+ done = 1;
}
- if (bytes_ > 0) {
- String rate = String.format("%6.1f MB/s", (bytes_ / 1048576.0) / elapsedSeconds);
- if (message_ != null) {
- message_ = rate + " " + message_;
+ if (bytes > 0) {
+ String rate = String.format("%6.1f MB/s", (bytes / 1048576.0) / elapsedSeconds);
+ if (message != null) {
+ message = rate + " " + message;
}
else {
- message_ = rate;
+ message = rate;
}
}
- else if (message_ == null) {
- message_ = "";
+ else if (message == null) {
+ message = "";
}
System.out.printf("%-12s : %11.5f micros/op;%s%s\n",
benchmark,
- elapsedSeconds * 1e6 / done_,
- (message_ == null ? "" : " "),
- message_);
+ elapsedSeconds * 1e6 / done,
+ (message == null ? "" : " "),
+ message);
// if (FLAGS_histogram) {
// System.out.printf("Microseconds per op:\n%s\n", hist_.ToString().c_str());
// }
- if (post_message_ != null) {
- System.out.printf("\n%s\n", post_message_);
- post_message_ = null;
+ if (postMessage != null) {
+ System.out.printf("\n%s\n", postMessage);
+ postMessage = null;
}
}
- private void write(WriteOptions writeOptions, Order order, DBState state, int numEntries, int valueSize, int entries_per_batch)
+ private void write(WriteOptions writeOptions, Order order, DBState state, int numEntries, int valueSize, int entriesPerBatch)
throws IOException
{
if (state == FRESH) {
if (useExisting) {
- message_ = "skipping (--use_existing_db is true)";
+ message = "skipping (--use_existing_db is true)";
return;
}
- db_.close();
- db_ = null;
+ db.close();
+ db = null;
destroyDb();
open();
start(); // Do not count time taken to destroy/open
}
- if (numEntries != num_) {
- message_ = String.format("(%d ops)", numEntries);
+ if (numEntries != num) {
+ message = String.format("(%d ops)", numEntries);
}
- for (int i = 0; i < numEntries; i += entries_per_batch) {
- WriteBatch batch = db_.createWriteBatch();
- for (int j = 0; j < entries_per_batch; j++) {
- int k = (order == SEQUENTIAL) ? i + j : rand_.nextInt(num_);
+ for (int i = 0; i < numEntries; i += entriesPerBatch) {
+ WriteBatch batch = db.createWriteBatch();
+ for (int j = 0; j < entriesPerBatch; j++) {
+ int k = (order == SEQUENTIAL) ? i + j : random.nextInt(num);
byte[] key = formatNumber(k);
- batch.put(key, gen_.generate(valueSize));
- bytes_ += valueSize + key.length;
+ batch.put(key, generator.generate(valueSize));
+ bytes += valueSize + key.length;
finishedSingleOp();
}
- db_.write(batch, writeOptions);
+ db.write(batch, writeOptions);
batch.close();
}
}
@@ -397,7 +397,7 @@ public static byte[] formatNumber(long n)
{
Preconditions.checkArgument(n >= 0, "number must be positive");
- byte []slice = new byte[16];
+ byte[] slice = new byte[16];
int i = 15;
while (n > 0) {
@@ -415,30 +415,30 @@ private void finishedSingleOp()
// if (histogram) {
// todo
// }
- done_++;
- if (done_ >= next_report_) {
- if (next_report_ < 1000) {
- next_report_ += 100;
+ done++;
+ if (done >= nextReport) {
+ if (nextReport < 1000) {
+ nextReport += 100;
}
- else if (next_report_ < 5000) {
- next_report_ += 500;
+ else if (nextReport < 5000) {
+ nextReport += 500;
}
- else if (next_report_ < 10000) {
- next_report_ += 1000;
+ else if (nextReport < 10000) {
+ nextReport += 1000;
}
- else if (next_report_ < 50000) {
- next_report_ += 5000;
+ else if (nextReport < 50000) {
+ nextReport += 5000;
}
- else if (next_report_ < 100000) {
- next_report_ += 10000;
+ else if (nextReport < 100000) {
+ nextReport += 10000;
}
- else if (next_report_ < 500000) {
- next_report_ += 50000;
+ else if (nextReport < 500000) {
+ nextReport += 50000;
}
else {
- next_report_ += 100000;
+ nextReport += 100000;
}
- System.out.printf("... finished %d ops%30s\r", done_, "");
+ System.out.printf("... finished %d ops%30s\r", done, "");
}
}
@@ -446,10 +446,10 @@ else if (next_report_ < 500000) {
private void readSequential()
{
for (int loops = 0; loops < 5; loops++) {
- DBIterator iterator = db_.iterator();
- for (int i = 0; i < reads_ && iterator.hasNext(); i++) {
+ DBIterator iterator = db.iterator();
+ for (int i = 0; i < reads && iterator.hasNext(); i++) {
Map.Entry entry = iterator.next();
- bytes_ += entry.getKey().length + entry.getValue().length;
+ bytes += entry.getKey().length + entry.getValue().length;
finishedSingleOp();
}
Closeables.closeQuietly(iterator);
@@ -463,22 +463,22 @@ private void readReverse()
private void readRandom()
{
- for (int i = 0; i < reads_; i++) {
- byte[] key = formatNumber(rand_.nextInt(num_));
- byte[] value = db_.get(key);
+ for (int i = 0; i < reads; i++) {
+ byte[] key = formatNumber(random.nextInt(num));
+ byte[] value = db.get(key);
Preconditions.checkNotNull(value, "db.get(%s) is null", new String(key, UTF_8));
- bytes_ += key.length + value.length;
+ bytes += key.length + value.length;
finishedSingleOp();
}
}
private void readHot()
{
- int range = (num_ + 99) / 100;
- for (int i = 0; i < reads_; i++) {
- byte[] key = formatNumber(rand_.nextInt(range));
- byte[] value = db_.get(key);
- bytes_ += key.length + value.length;
+ int range = (num + 99) / 100;
+ for (int i = 0; i < reads; i++) {
+ byte[] key = formatNumber(random.nextInt(range));
+ byte[] value = db.get(key);
+ bytes += key.length + value.length;
finishedSingleOp();
}
}
@@ -486,10 +486,10 @@ private void readHot()
private void compact()
throws IOException
{
- if(db_ instanceof DbImpl) {
- ((DbImpl)db_).compactMemTable();
+ if (db instanceof DbImpl) {
+ ((DbImpl) db).compactMemTable();
for (int level = 0; level < NUM_LEVELS - 1; level++) {
- ((DbImpl)db_).compactRange(level, Slices.copiedBuffer("", UTF_8), Slices.copiedBuffer("~", UTF_8));
+ ((DbImpl) db).compactRange(level, Slices.copiedBuffer("", UTF_8), Slices.copiedBuffer("~", UTF_8));
}
}
}
@@ -514,9 +514,9 @@ private void crc32c(int blockSize, String message)
}
System.out.printf("... crc=0x%x\r", crc);
- bytes_ = bytes;
+ this.bytes = bytes;
// Print so result is not dead
- message_ = message;
+ this.message = message;
}
private void acquireLoad()
@@ -526,16 +526,16 @@ private void acquireLoad()
private void snappyCompress()
{
- byte[] raw = gen_.generate(new Options().blockSize());
+ byte[] raw = generator.generate(new Options().blockSize());
byte[] compressedOutput = new byte[Snappy.maxCompressedLength(raw.length)];
long produced = 0;
// attempt to compress the block
- while (bytes_ < 1024 * 1048576) { // Compress 1G
+ while (bytes < 1024 * 1048576) { // Compress 1G
try {
int compressedSize = Snappy.compress(raw, 0, raw.length, compressedOutput, 0);
- bytes_ += raw.length;
+ bytes += raw.length;
produced += compressedSize;
}
catch (IOException ignored) {
@@ -545,14 +545,14 @@ private void snappyCompress()
finishedSingleOp();
}
- message_ = String.format("(output: %.1f%%)", (produced * 100.0) / bytes_);
+ message = String.format("(output: %.1f%%)", (produced * 100.0) / bytes);
}
private void snappyUncompressArray()
{
int inputSize = new Options().blockSize();
byte[] compressedOutput = new byte[Snappy.maxCompressedLength(inputSize)];
- byte raw[] = gen_.generate(inputSize);
+ byte[] raw = generator.generate(inputSize);
int compressedLength;
try {
compressedLength = Snappy.compress(raw, 0, raw.length, compressedOutput, 0);
@@ -561,10 +561,10 @@ private void snappyUncompressArray()
throw Throwables.propagate(e);
}
// attempt to uncompress the block
- while (bytes_ < 5L * 1024 * 1048576) { // Compress 1G
+ while (bytes < 5L * 1024 * 1048576) { // Compress 1G
try {
Snappy.uncompress(compressedOutput, 0, compressedLength, raw, 0);
- bytes_ += inputSize;
+ bytes += inputSize;
}
catch (IOException ignored) {
throw Throwables.propagate(ignored);
@@ -578,7 +578,7 @@ private void snappyUncompressDirectBuffer()
{
int inputSize = new Options().blockSize();
byte[] compressedOutput = new byte[Snappy.maxCompressedLength(inputSize)];
- byte raw[] = gen_.generate(inputSize);
+ byte[] raw = generator.generate(inputSize);
int compressedLength;
try {
compressedLength = Snappy.compress(raw, 0, raw.length, compressedOutput, 0);
@@ -592,13 +592,13 @@ private void snappyUncompressDirectBuffer()
compressedBuffer.put(compressedOutput, 0, compressedLength);
// attempt to uncompress the block
- while (bytes_ < 5L * 1024 * 1048576) { // Compress 1G
+ while (bytes < 5L * 1024 * 1048576) { // Compress 1G
try {
uncompressedBuffer.clear();
compressedBuffer.position(0);
compressedBuffer.limit(compressedLength);
Snappy.uncompress(compressedBuffer, uncompressedBuffer);
- bytes_ += inputSize;
+ bytes += inputSize;
}
catch (IOException ignored) {
throw Throwables.propagate(ignored);
@@ -615,8 +615,8 @@ private void heapProfile()
private void destroyDb()
{
- Closeables.closeQuietly(db_);
- db_ = null;
+ Closeables.closeQuietly(db);
+ db = null;
FileUtils.deleteRecursively(databaseDir);
}
@@ -637,9 +637,6 @@ public static void main(String[] args)
if (arg.startsWith("--")) {
try {
ImmutableList parts = ImmutableList.copyOf(Splitter.on("=").limit(2).split(arg.substring(2)));
- if (parts.size() != 2) {
-
- }
Flag key = Flag.valueOf(parts.get(0));
Object value = key.parseValue(parts.get(1));
flags.put(key, value);
@@ -658,7 +655,6 @@ public static void main(String[] args)
new DbBenchmark(flags).run();
}
-
private enum Flag
{
// Comma-separated list of operations to run in the specified order
@@ -812,11 +808,11 @@ public Object parseValue(String value)
{
return value;
}
- },;
+ };
private final Object defaultValue;
- private Flag(Object defaultValue)
+ Flag(Object defaultValue)
{
this.defaultValue = defaultValue;
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/Compaction.java b/leveldb/src/main/java/org/iq80/leveldb/impl/Compaction.java
index cfdfa29c..d0519419 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/Compaction.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/Compaction.java
@@ -69,7 +69,7 @@ public Compaction(Version inputVersion, int level, List levelInput
this.levelUpInputs = levelUpInputs;
this.grandparents = grandparents;
this.maxOutputFileSize = VersionSet.maxFileSizeForLevel(level);
- this.inputs = new List[]{levelInputs, levelUpInputs};
+ this.inputs = new List[] {levelInputs, levelUpInputs};
}
public int getLevel()
@@ -178,9 +178,7 @@ public boolean shouldStopBefore(InternalKey internalKey)
// Scan to find earliest grandparent file that contains key.
InternalKeyComparator internalKeyComparator = inputVersion.getInternalKeyComparator();
- while (grandparentIndex < grandparents.size() &&
- internalKeyComparator.compare(internalKey, grandparents.get(grandparentIndex).getLargest()) > 0) {
-
+ while (grandparentIndex < grandparents.size() && internalKeyComparator.compare(internalKey, grandparents.get(grandparentIndex).getLargest()) > 0) {
if (seenKey) {
overlappedBytes += grandparents.get(grandparentIndex).getFileSize();
}
@@ -198,7 +196,8 @@ public boolean shouldStopBefore(InternalKey internalKey)
}
}
- public List[] getInputs() {
+ public List[] getInputs()
+ {
return inputs;
}
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/DbConstants.java b/leveldb/src/main/java/org/iq80/leveldb/impl/DbConstants.java
index 36d2aae3..be4f48c5 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/DbConstants.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/DbConstants.java
@@ -17,7 +17,7 @@
*/
package org.iq80.leveldb.impl;
-public class DbConstants
+public final class DbConstants
{
public static final int MAJOR_VERSION = 0;
public static final int MINOR_VERSION = 1;
@@ -54,4 +54,7 @@ public class DbConstants
*/
public static final int MAX_MEM_COMPACT_LEVEL = 2;
+ private DbConstants()
+ {
+ }
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/DbImpl.java b/leveldb/src/main/java/org/iq80/leveldb/impl/DbImpl.java
index f332872f..28cfca44 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/DbImpl.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/DbImpl.java
@@ -80,7 +80,8 @@
import static org.iq80.leveldb.util.Slices.writeLengthPrefixedBytes;
// todo make thread safe and concurrent
-public class DbImpl implements DB
+public class DbImpl
+ implements DB
{
private final Options options;
private final File databaseDir;
@@ -114,7 +115,7 @@ public DbImpl(Options options, File databaseDir)
Preconditions.checkNotNull(databaseDir, "databaseDir is null");
this.options = options;
- if( this.options.compressionType() == CompressionType.SNAPPY && !Snappy.available() ) {
+ if (this.options.compressionType() == CompressionType.SNAPPY && !Snappy.available()) {
// Disable snappy if it's not available.
this.options.compressionType(CompressionType.NONE);
}
@@ -126,15 +127,14 @@ public DbImpl(Options options, File databaseDir)
UserComparator userComparator;
if (comparator != null) {
userComparator = new CustomUserComparator(comparator);
- }else{
+ }
+ else {
userComparator = new BytewiseComparator();
}
internalKeyComparator = new InternalKeyComparator(userComparator);
memTable = new MemTable(internalKeyComparator);
immutableMemTable = null;
-
-
ThreadFactory compactionThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("leveldb-compaction-%s")
.setUncaughtExceptionHandler(new UncaughtExceptionHandler()
@@ -231,7 +231,8 @@ public void uncaughtException(Thread t, Throwable e)
}
}
- public void close() {
+ public void close()
+ {
if (shuttingDown.getAndSet(true)) {
return;
}
@@ -241,7 +242,8 @@ public void close() {
while (backgroundCompaction != null) {
backgroundCondition.awaitUninterruptibly();
}
- } finally {
+ }
+ finally {
mutex.unlock();
}
@@ -285,8 +287,9 @@ private void deleteObsoleteFiles()
for (File file : Filename.listFiles(databaseDir)) {
FileInfo fileInfo = Filename.parseFileName(file);
- if (fileInfo == null)
- continue;
+ if (fileInfo == null) {
+ continue;
+ }
long number = fileInfo.getFileNumber();
boolean keep = true;
switch (fileInfo.getFileType()) {
@@ -326,6 +329,7 @@ private void deleteObsoleteFiles()
}
}
}
+
public void flushMemTable()
{
mutex.lock();
@@ -334,11 +338,12 @@ public void flushMemTable()
makeRoomForWrite(true);
// todo bg_error code
- while(immutableMemTable != null) {
+ while (immutableMemTable != null) {
backgroundCondition.awaitUninterruptibly();
}
- } finally {
+ }
+ finally {
mutex.unlock();
}
}
@@ -396,7 +401,8 @@ public Void call()
backgroundCall();
}
catch (DatabaseShutdownException ignored) {
- } catch (Throwable e) {
+ }
+ catch (Throwable e) {
backgroundException = e;
}
return null;
@@ -404,10 +410,11 @@ public Void call()
});
}
}
-
- public void checkBackgroundException() {
+
+ public void checkBackgroundException()
+ {
Throwable e = backgroundException;
- if(e!=null) {
+ if (e != null) {
throw new BackgroundProcessingException(e);
}
}
@@ -459,13 +466,15 @@ private void backgroundCompaction()
compaction = versions.compactRange(manualCompaction.level,
new InternalKey(manualCompaction.begin, MAX_SEQUENCE_NUMBER, ValueType.VALUE),
new InternalKey(manualCompaction.end, 0, ValueType.DELETION));
- } else {
+ }
+ else {
compaction = versions.pickCompaction();
}
if (compaction == null) {
// no compaction
- } else if (manualCompaction == null && compaction.isTrivialMove()) {
+ }
+ else if (manualCompaction == null && compaction.isTrivialMove()) {
// Move file to next level
Preconditions.checkState(compaction.getLevelInputs().size() == 1);
FileMetaData fileMetaData = compaction.getLevelInputs().get(0);
@@ -473,7 +482,8 @@ private void backgroundCompaction()
compaction.getEdit().addFile(compaction.getLevel() + 1, fileMetaData);
versions.logAndApply(compaction.getEdit());
// log
- } else {
+ }
+ else {
CompactionState compactionState = new CompactionState(compaction);
doCompactionWork(compactionState);
cleanupCompaction(compactionState);
@@ -491,7 +501,8 @@ private void cleanupCompaction(CompactionState compactionState)
if (compactionState.builder != null) {
compactionState.builder.abandon();
- } else {
+ }
+ else {
Preconditions.checkArgument(compactionState.outfile == null);
}
@@ -553,8 +564,9 @@ private long recoverLogFile(long fileNumber, VersionEdit edit)
}
return maxSequence;
- } finally {
- channel.close();
+ }
+ finally {
+ channel.close();
}
}
@@ -589,10 +601,10 @@ public byte[] get(byte[] key, ReadOptions options)
lookupResult = immutableMemTable.get(lookupKey);
if (lookupResult != null) {
Slice value = lookupResult.getValue();
- if (value == null) {
- return null;
- }
- return value.getBytes();
+ if (value == null) {
+ return null;
+ }
+ return value.getBytes();
}
}
}
@@ -693,13 +705,15 @@ public Snapshot writeInternal(WriteBatchImpl updates, WriteOptions options)
// Update memtable
updates.forEach(new InsertIntoHandler(memTable, sequenceBegin));
- } else {
+ }
+ else {
sequenceEnd = versions.getLastSequence();
}
- if(options.snapshot()) {
+ if (options.snapshot()) {
return new SnapshotImpl(versions.getCurrent(), sequenceEnd);
- } else {
+ }
+ else {
return null;
}
}
@@ -728,7 +742,6 @@ public SeekingIteratorAdapter iterator(ReadOptions options)
try {
DbIterator rawIterator = internalIterator();
-
// filter any entries not visible in our snapshot
SnapshotImpl snapshot = getSnapshot(options);
SnapshotSeekingIterator snapshotIterator = new SnapshotSeekingIterator(rawIterator, snapshot, internalKeyComparator.getUserComparator());
@@ -820,7 +833,8 @@ private void makeRoomForWrite(boolean force)
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
- } finally {
+ }
+ finally {
mutex.lock();
}
@@ -853,7 +867,6 @@ else if (versions.numberOfFilesInLevel(0) >= L0_STOP_WRITES_TRIGGER) {
throw new RuntimeException("Unable to close log file " + log.getFile(), e);
}
-
// open a new log
long logNumber = versions.getNextFileNumber();
try {
@@ -937,7 +950,8 @@ private void writeLevel0Table(MemTable mem, VersionEdit edit, Version base)
FileMetaData meta;
try {
meta = buildTable(mem, fileNumber);
- } finally {
+ }
+ finally {
mutex.lock();
}
pendingOutputs.remove(fileNumber);
@@ -957,7 +971,7 @@ private void writeLevel0Table(MemTable mem, VersionEdit edit, Version base)
private FileMetaData buildTable(SeekingIterable data, long fileNumber)
throws IOException
- {
+ {
File file = new File(databaseDir, Filename.tableFileName(fileNumber));
try {
InternalKey smallest = null;
@@ -966,7 +980,6 @@ private FileMetaData buildTable(SeekingIterable data, long f
try {
TableBuilder tableBuilder = new TableBuilder(options, channel, new InternalUserComparator(internalKeyComparator));
-
for (Entry entry : data) {
// update keys
InternalKey key = entry.getKey();
@@ -979,10 +992,12 @@ private FileMetaData buildTable(SeekingIterable data, long f
}
tableBuilder.finish();
- } finally {
+ }
+ finally {
try {
channel.force(true);
- } finally {
+ }
+ finally {
channel.close();
}
}
@@ -1004,7 +1019,7 @@ private FileMetaData buildTable(SeekingIterable data, long f
file.delete();
throw e;
}
- }
+ }
private void doCompactionWork(CompactionState compactionState)
throws IOException
@@ -1065,7 +1080,6 @@ private void doCompactionWork(CompactionState compactionState)
else if (key.getValueType() == ValueType.DELETION &&
key.getSequenceNumber() <= compactionState.smallestSnapshot &&
compactionState.compaction.isBaseLevelForKey(key.getUserKey())) {
-
// For this user key:
// (1) there is no data in higher levels
// (2) data in lower levels will have larger sequence numbers
@@ -1294,10 +1308,12 @@ private WriteBatchImpl readWriteBatch(SliceInput record, int updateSize)
Slice key = readLengthPrefixedBytes(record);
Slice value = readLengthPrefixedBytes(record);
writeBatch.put(key, value);
- } else if (valueType == DELETION) {
+ }
+ else if (valueType == DELETION) {
Slice key = readLengthPrefixedBytes(record);
writeBatch.delete(key);
- } else {
+ }
+ else {
throw new IllegalStateException("Unexpected value type " + valueType);
}
}
@@ -1335,7 +1351,8 @@ public void delete(Slice key)
return record.slice(0, sliceOutput.size());
}
- private static class InsertIntoHandler implements Handler
+ private static class InsertIntoHandler
+ implements Handler
{
private long sequence;
private final MemTable memTable;
@@ -1359,7 +1376,9 @@ public void delete(Slice key)
}
}
- public static class DatabaseShutdownException extends DBException {
+ public static class DatabaseShutdownException
+ extends DBException
+ {
public DatabaseShutdownException()
{
}
@@ -1369,51 +1388,61 @@ public DatabaseShutdownException(String message)
super(message);
}
}
-
- public static class BackgroundProcessingException extends DBException {
+
+ public static class BackgroundProcessingException
+ extends DBException
+ {
public BackgroundProcessingException(Throwable cause)
{
super(cause);
}
}
- private Object suspensionMutex = new Object();
- private int suspensionCounter=0;
+ private final Object suspensionMutex = new Object();
+ private int suspensionCounter = 0;
@Override
- public void suspendCompactions() throws InterruptedException {
- compactionExecutor.execute(new Runnable() {
+ public void suspendCompactions()
+ throws InterruptedException
+ {
+ compactionExecutor.execute(new Runnable()
+ {
@Override
- public void run() {
+ public void run()
+ {
try {
synchronized (suspensionMutex) {
- suspensionCounter ++;
+ suspensionCounter++;
suspensionMutex.notifyAll();
- while( suspensionCounter > 0 && !compactionExecutor.isShutdown()) {
+ while (suspensionCounter > 0 && !compactionExecutor.isShutdown()) {
suspensionMutex.wait(500);
}
}
- } catch (InterruptedException e) {
+ }
+ catch (InterruptedException e) {
}
}
});
synchronized (suspensionMutex) {
- while(suspensionCounter < 1) {
+ while (suspensionCounter < 1) {
suspensionMutex.wait();
}
}
}
@Override
- public void resumeCompactions() {
+ public void resumeCompactions()
+ {
synchronized (suspensionMutex) {
- suspensionCounter --;
+ suspensionCounter--;
suspensionMutex.notifyAll();
}
}
@Override
- public void compactRange(byte[] begin, byte[] end) throws DBException {
+ public void compactRange(byte[] begin, byte[] end)
+ throws DBException
+ {
throw new UnsupportedOperationException("Not yet implemented");
}
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/FileChannelLogWriter.java b/leveldb/src/main/java/org/iq80/leveldb/impl/FileChannelLogWriter.java
index a1d204d3..27405fcc 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/FileChannelLogWriter.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/FileChannelLogWriter.java
@@ -35,7 +35,8 @@
import static org.iq80.leveldb.impl.LogConstants.BLOCK_SIZE;
import static org.iq80.leveldb.impl.LogConstants.HEADER_SIZE;
-public class FileChannelLogWriter implements LogWriter
+public class FileChannelLogWriter
+ implements LogWriter
{
private final File file;
private final long fileNumber;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/FileMetaData.java b/leveldb/src/main/java/org/iq80/leveldb/impl/FileMetaData.java
index f0887e5c..b1de3b0c 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/FileMetaData.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/FileMetaData.java
@@ -23,7 +23,7 @@
public class FileMetaData
{
- public static Function GET_LARGEST_USER_KEY = new Function()
+ public static final Function GET_LARGEST_USER_KEY = new Function()
{
@Override
public InternalKey apply(FileMetaData fileMetaData)
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/Filename.java b/leveldb/src/main/java/org/iq80/leveldb/impl/Filename.java
index e3f7ba2c..4d1269a2 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/Filename.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/Filename.java
@@ -26,8 +26,12 @@
import java.io.IOException;
import java.util.List;
-public class Filename
+public final class Filename
{
+ private Filename()
+ {
+ }
+
public enum FileType
{
LOG,
@@ -153,6 +157,7 @@ else if (fileName.endsWith(".dbtmp")) {
/**
* Make the CURRENT file point to the descriptor file with the
* specified number.
+ *
* @return true if successful; false otherwise
*/
public static boolean setCurrentFile(File databaseDir, long descriptorNumber)
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/InternalEntry.java b/leveldb/src/main/java/org/iq80/leveldb/impl/InternalEntry.java
index 78f765d8..db96aa40 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/InternalEntry.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/InternalEntry.java
@@ -25,7 +25,8 @@
import static com.google.common.base.Charsets.UTF_8;
-public class InternalEntry implements Entry
+public class InternalEntry
+ implements Entry
{
public static final Function GET_KEY = new Function()
{
@@ -59,7 +60,6 @@ public Slice getValue()
return value;
}
-
/**
* @throws UnsupportedOperationException always
*/
@@ -110,4 +110,3 @@ public String toString()
return sb.toString();
}
}
-
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/InternalKey.java b/leveldb/src/main/java/org/iq80/leveldb/impl/InternalKey.java
index 186f75f2..3c43af9a 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/InternalKey.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/InternalKey.java
@@ -20,8 +20,8 @@
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import org.iq80.leveldb.util.Slice;
-import org.iq80.leveldb.util.Slices;
import org.iq80.leveldb.util.SliceOutput;
+import org.iq80.leveldb.util.Slices;
import static com.google.common.base.Charsets.UTF_8;
import static org.iq80.leveldb.util.SizeOf.SIZE_OF_LONG;
@@ -108,6 +108,7 @@ public boolean equals(Object o)
}
private int hash = 0;
+
@Override
public int hashCode()
{
@@ -148,8 +149,8 @@ public static Function createUserKeyToInternalKeyFunction(fi
return new UserKeyInternalKeyFunction(sequenceNumber);
}
-
- private static class InternalKeyToSliceFunction implements Function
+ private static class InternalKeyToSliceFunction
+ implements Function
{
@Override
public Slice apply(InternalKey internalKey)
@@ -158,7 +159,8 @@ public Slice apply(InternalKey internalKey)
}
}
- private static class InternalKeyToUserKeyFunction implements Function
+ private static class InternalKeyToUserKeyFunction
+ implements Function
{
@Override
public Slice apply(InternalKey internalKey)
@@ -167,7 +169,8 @@ public Slice apply(InternalKey internalKey)
}
}
- private static class SliceToInternalKeyFunction implements Function
+ private static class SliceToInternalKeyFunction
+ implements Function
{
@Override
public InternalKey apply(Slice bytes)
@@ -176,7 +179,8 @@ public InternalKey apply(Slice bytes)
}
}
- private static class UserKeyInternalKeyFunction implements Function
+ private static class UserKeyInternalKeyFunction
+ implements Function
{
private final long sequenceNumber;
@@ -206,6 +210,4 @@ private static ValueType getValueType(Slice data)
{
return SequenceNumber.unpackValueType(data.getLong(data.length() - SIZE_OF_LONG));
}
-
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/InternalKeyComparator.java b/leveldb/src/main/java/org/iq80/leveldb/impl/InternalKeyComparator.java
index 29709eaf..553e3a58 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/InternalKeyComparator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/InternalKeyComparator.java
@@ -17,7 +17,6 @@
*/
package org.iq80.leveldb.impl;
-import com.google.common.collect.ComparisonChain;
import com.google.common.primitives.Longs;
import org.iq80.leveldb.table.UserComparator;
@@ -25,7 +24,8 @@
import java.util.Comparator;
import java.util.Iterator;
-public class InternalKeyComparator implements Comparator
+public class InternalKeyComparator
+ implements Comparator
{
private final UserComparator userComparator;
@@ -39,7 +39,8 @@ public UserComparator getUserComparator()
return userComparator;
}
- public String name() {
+ public String name()
+ {
return this.userComparator.name();
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/InternalUserComparator.java b/leveldb/src/main/java/org/iq80/leveldb/impl/InternalUserComparator.java
index 489e2d9d..06a3eb20 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/InternalUserComparator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/InternalUserComparator.java
@@ -23,7 +23,8 @@
import static org.iq80.leveldb.impl.SequenceNumber.MAX_SEQUENCE_NUMBER;
-public class InternalUserComparator implements UserComparator
+public class InternalUserComparator
+ implements UserComparator
{
private final InternalKeyComparator internalKeyComparator;
@@ -39,7 +40,8 @@ public int compare(Slice left, Slice right)
}
@Override
- public String name() {
+ public String name()
+ {
return internalKeyComparator.name();
}
@@ -58,8 +60,8 @@ public Slice findShortestSeparator(
// User key has become larger. Tack on the earliest possible
// number to the shortened user key.
InternalKey newInternalKey = new InternalKey(shortestSeparator, MAX_SEQUENCE_NUMBER, ValueType.VALUE);
- Preconditions.checkState(compare(start, newInternalKey.encode()) < 0);// todo
- Preconditions.checkState(compare(newInternalKey.encode(), limit) < 0);// todo
+ Preconditions.checkState(compare(start, newInternalKey.encode()) < 0); // todo
+ Preconditions.checkState(compare(newInternalKey.encode(), limit) < 0); // todo
return newInternalKey.encode();
}
@@ -77,7 +79,7 @@ public Slice findShortSuccessor(Slice key)
// User key has become larger. Tack on the earliest possible
// number to the shortened user key.
InternalKey newInternalKey = new InternalKey(shortSuccessor, MAX_SEQUENCE_NUMBER, ValueType.VALUE);
- Preconditions.checkState(compare(key, newInternalKey.encode()) < 0);// todo
+ Preconditions.checkState(compare(key, newInternalKey.encode()) < 0); // todo
return newInternalKey.encode();
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/Iq80DBFactory.java b/leveldb/src/main/java/org/iq80/leveldb/impl/Iq80DBFactory.java
index 46b881ec..e5a6bc07 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/Iq80DBFactory.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/Iq80DBFactory.java
@@ -22,31 +22,41 @@
import org.iq80.leveldb.Options;
import org.iq80.leveldb.util.FileUtils;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
/**
* @author Hiram Chirino
*/
-public class Iq80DBFactory implements DBFactory {
-
+public class Iq80DBFactory
+ implements DBFactory
+{
public static final int CPU_DATA_MODEL = Integer.getInteger("sun.arch.data.model");
// We only use MMAP on 64 bit systems since it's really easy to run out of
// virtual address space on a 32 bit system when all the data is getting mapped
// into memory. If you really want to use MMAP anyways, use -Dleveldb.mmap=true
- public static final boolean USE_MMAP = Boolean.parseBoolean(System.getProperty("leveldb.mmap", ""+(CPU_DATA_MODEL>32)));
+ public static final boolean USE_MMAP = Boolean.parseBoolean(System.getProperty("leveldb.mmap", "" + (CPU_DATA_MODEL > 32)));
public static final String VERSION;
+
static {
- String v="unknown";
+ String v = "unknown";
InputStream is = Iq80DBFactory.class.getResourceAsStream("version.txt");
try {
v = new BufferedReader(new InputStreamReader(is, "UTF-8")).readLine();
- } catch (Throwable e) {
- } finally {
+ }
+ catch (Throwable e) {
+ }
+ finally {
try {
is.close();
- } catch (Throwable e) {
+ }
+ catch (Throwable e) {
}
}
VERSION = v;
@@ -55,46 +65,56 @@ public class Iq80DBFactory implements DBFactory {
public static final Iq80DBFactory factory = new Iq80DBFactory();
@Override
- public DB open(File path, Options options) throws IOException {
+ public DB open(File path, Options options)
+ throws IOException
+ {
return new DbImpl(options, path);
}
@Override
- public void destroy(File path, Options options) throws IOException {
+ public void destroy(File path, Options options)
+ throws IOException
+ {
// TODO: This should really only delete leveldb-created files.
FileUtils.deleteRecursively(path);
}
@Override
- public void repair(File path, Options options) throws IOException {
+ public void repair(File path, Options options)
+ throws IOException
+ {
throw new UnsupportedOperationException();
}
@Override
- public String toString() {
+ public String toString()
+ {
return String.format("iq80 leveldb version %s", VERSION);
}
- public static byte[] bytes(String value) {
- if( value == null) {
+ public static byte[] bytes(String value)
+ {
+ if (value == null) {
return null;
}
try {
return value.getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
- public static String asString(byte value[]) {
- if( value == null) {
+ public static String asString(byte[] value)
+ {
+ if (value == null) {
return null;
}
try {
return new String(value, "UTF-8");
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/Level.java b/leveldb/src/main/java/org/iq80/leveldb/impl/Level.java
index 5b31e39d..e67df6e3 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/Level.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/Level.java
@@ -36,7 +36,8 @@
import static org.iq80.leveldb.impl.ValueType.VALUE;
// todo this class should be immutable
-public class Level implements SeekingIterable
+public class Level
+ implements SeekingIterable
{
private final int levelNumber;
private final TableCache tableCache;
@@ -116,8 +117,7 @@ public LookupResult get(LookupKey key, ReadStats readStats)
int lastFileReadLevel = -1;
readStats.clear();
for (FileMetaData fileMetaData : fileMetaDataList) {
-
- if (lastFileRead!=null && readStats.getSeekFile() == null) {
+ if (lastFileRead != null && readStats.getSeekFile() == null) {
// We have had more than one seek for this read. Charge the first file.
readStats.setSeekFile(lastFileRead);
readStats.setSeekFileLevel(lastFileReadLevel);
@@ -148,7 +148,6 @@ else if (internalKey.getValueType() == VALUE) {
}
}
}
-
}
return null;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/Level0.java b/leveldb/src/main/java/org/iq80/leveldb/impl/Level0.java
index 1964e35c..a314de96 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/Level0.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/Level0.java
@@ -35,15 +35,18 @@
import static org.iq80.leveldb.impl.ValueType.VALUE;
// todo this class should be immutable
-public class Level0 implements SeekingIterable
+public class Level0
+ implements SeekingIterable
{
private final TableCache tableCache;
private final InternalKeyComparator internalKeyComparator;
private final List files;
- public static final Comparator NEWEST_FIRST = new Comparator() {
+ public static final Comparator NEWEST_FIRST = new Comparator()
+ {
@Override
- public int compare(FileMetaData fileMetaData, FileMetaData fileMetaData1) {
+ public int compare(FileMetaData fileMetaData, FileMetaData fileMetaData1)
+ {
return (int) (fileMetaData1.getNumber() - fileMetaData.getNumber());
}
};
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/LogChunkType.java b/leveldb/src/main/java/org/iq80/leveldb/impl/LogChunkType.java
index 8a86d4e2..8354a9a9 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/LogChunkType.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/LogChunkType.java
@@ -18,7 +18,6 @@
package org.iq80.leveldb.impl;
import com.google.common.base.Preconditions;
-import org.iq80.leveldb.util.PureJavaCrc32C;
public enum LogChunkType
{
@@ -31,7 +30,8 @@ public enum LogChunkType
BAD_CHUNK,
UNKNOWN;
- public static LogChunkType getLogChunkTypeByPersistentId(int persistentId) {
+ public static LogChunkType getLogChunkTypeByPersistentId(int persistentId)
+ {
for (LogChunkType logChunkType : LogChunkType.values()) {
if (logChunkType.persistentId != null && logChunkType.persistentId == persistentId) {
return logChunkType;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/LogConstants.java b/leveldb/src/main/java/org/iq80/leveldb/impl/LogConstants.java
index b17e03c7..8fe304b4 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/LogConstants.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/LogConstants.java
@@ -17,8 +17,6 @@
*/
package org.iq80.leveldb.impl;
-import org.iq80.leveldb.util.SizeOf;
-
import static org.iq80.leveldb.util.SizeOf.SIZE_OF_BYTE;
import static org.iq80.leveldb.util.SizeOf.SIZE_OF_INT;
import static org.iq80.leveldb.util.SizeOf.SIZE_OF_SHORT;
@@ -32,4 +30,7 @@ public final class LogConstants
// Header is checksum (4 bytes), type (1 byte), length (2 bytes).
public static final int HEADER_SIZE = SIZE_OF_INT + SIZE_OF_BYTE + SIZE_OF_SHORT;
+ private LogConstants()
+ {
+ }
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/LogMonitor.java b/leveldb/src/main/java/org/iq80/leveldb/impl/LogMonitor.java
index dc5725b8..9a4c03c1 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/LogMonitor.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/LogMonitor.java
@@ -20,5 +20,6 @@
public interface LogMonitor
{
public void corruption(long bytes, String reason);
+
public void corruption(long bytes, Throwable reason);
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/LogMonitors.java b/leveldb/src/main/java/org/iq80/leveldb/impl/LogMonitors.java
index d2163102..b13e4d53 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/LogMonitors.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/LogMonitors.java
@@ -19,7 +19,8 @@
public final class LogMonitors
{
- public static LogMonitor throwExceptionMonitor() {
+ public static LogMonitor throwExceptionMonitor()
+ {
return new LogMonitor()
{
@Override
@@ -37,7 +38,8 @@ public void corruption(long bytes, Throwable reason)
}
// todo implement real logging
- public static LogMonitor logMonitor() {
+ public static LogMonitor logMonitor()
+ {
return new LogMonitor()
{
@Override
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/LogReader.java b/leveldb/src/main/java/org/iq80/leveldb/impl/LogReader.java
index be2c903e..85c125cb 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/LogReader.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/LogReader.java
@@ -20,8 +20,8 @@
import org.iq80.leveldb.util.DynamicSliceOutput;
import org.iq80.leveldb.util.Slice;
import org.iq80.leveldb.util.SliceInput;
-import org.iq80.leveldb.util.Slices;
import org.iq80.leveldb.util.SliceOutput;
+import org.iq80.leveldb.util.Slices;
import java.io.IOException;
import java.nio.channels.FileChannel;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/Logs.java b/leveldb/src/main/java/org/iq80/leveldb/impl/Logs.java
index da17761b..5bf617b8 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/Logs.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/Logs.java
@@ -17,8 +17,8 @@
*/
package org.iq80.leveldb.impl;
-import org.iq80.leveldb.util.Slice;
import org.iq80.leveldb.util.PureJavaCrc32C;
+import org.iq80.leveldb.util.Slice;
import java.io.File;
import java.io.IOException;
@@ -32,9 +32,10 @@ private Logs()
public static LogWriter createLogWriter(File file, long fileNumber)
throws IOException
{
- if( Iq80DBFactory.USE_MMAP ) {
+ if (Iq80DBFactory.USE_MMAP) {
return new MMapLogWriter(file, fileNumber);
- } else {
+ }
+ else {
return new FileChannelLogWriter(file, fileNumber);
}
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/LookupResult.java b/leveldb/src/main/java/org/iq80/leveldb/impl/LookupResult.java
index c1ac0197..938b8fb1 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/LookupResult.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/LookupResult.java
@@ -42,7 +42,8 @@ private LookupResult(LookupKey key, Slice value, boolean deleted)
this.key = key;
if (value != null) {
this.value = value.slice();
- } else {
+ }
+ else {
this.value = null;
}
this.deleted = deleted;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/MMapLogWriter.java b/leveldb/src/main/java/org/iq80/leveldb/impl/MMapLogWriter.java
index f2114a21..d2cb60fa 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/MMapLogWriter.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/MMapLogWriter.java
@@ -37,9 +37,10 @@
import static org.iq80.leveldb.impl.LogConstants.HEADER_SIZE;
import static org.iq80.leveldb.impl.Logs.getChunkChecksum;
-public class MMapLogWriter implements LogWriter
+public class MMapLogWriter
+ implements LogWriter
{
- private static final int PAGE_SIZE = 1024 * 1024;
+ private static final int PAGE_SIZE = 1024 * 1024;
private final File file;
private final long fileNumber;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/MemTable.java b/leveldb/src/main/java/org/iq80/leveldb/impl/MemTable.java
index 38e7d457..3b0d9b51 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/MemTable.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/MemTable.java
@@ -29,7 +29,8 @@
import static org.iq80.leveldb.util.SizeOf.SIZE_OF_LONG;
-public class MemTable implements SeekingIterable
+public class MemTable
+ implements SeekingIterable
{
private final ConcurrentSkipListMap table;
private final AtomicLong approximateMemoryUsage = new AtomicLong();
@@ -75,7 +76,8 @@ public LookupResult get(LookupKey key)
if (entryKey.getUserKey().equals(key.getUserKey())) {
if (entryKey.getValueType() == ValueType.DELETION) {
return LookupResult.deleted(key);
- } else {
+ }
+ else {
return LookupResult.ok(key, entry.getValue());
}
}
@@ -88,9 +90,9 @@ public MemTableIterator iterator()
return new MemTableIterator();
}
- public class MemTableIterator implements InternalIterator
+ public class MemTableIterator
+ implements InternalIterator
{
-
private PeekingIterator> iterator;
public MemTableIterator()
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/ReadStats.java b/leveldb/src/main/java/org/iq80/leveldb/impl/ReadStats.java
index 6583a88a..f25e110b 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/ReadStats.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/ReadStats.java
@@ -22,7 +22,8 @@ public class ReadStats
private int seekFileLevel = -1;
private FileMetaData seekFile;
- public void clear() {
+ public void clear()
+ {
seekFileLevel = -1;
seekFile = null;
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIterable.java b/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIterable.java
index e63ce94b..60a5c017 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIterable.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIterable.java
@@ -19,7 +19,8 @@
import java.util.Map.Entry;
-public interface SeekingIterable extends Iterable>
+public interface SeekingIterable
+ extends Iterable>
{
@Override
SeekingIterator iterator();
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIterator.java b/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIterator.java
index f56f112d..2d247bf2 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIterator.java
@@ -21,7 +21,8 @@
import java.util.Map.Entry;
-public interface SeekingIterator extends PeekingIterator>
+public interface SeekingIterator
+ extends PeekingIterator>
{
/**
* Repositions the iterator so the beginning of this block.
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIteratorAdapter.java b/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIteratorAdapter.java
index 5741e391..8382a877 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIteratorAdapter.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/SeekingIteratorAdapter.java
@@ -25,7 +25,8 @@
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
-public class SeekingIteratorAdapter implements DBIterator
+public class SeekingIteratorAdapter
+ implements DBIterator
{
private final SnapshotSeekingIterator seekingIterator;
private final AtomicBoolean closed = new AtomicBoolean(false);
@@ -70,7 +71,7 @@ public void close()
{
// This is an end user API.. he might screw up and close multiple times.
// but we don't want the close multiple times as reference counts go bad.
- if(closed.compareAndSet(false, true)) {
+ if (closed.compareAndSet(false, true)) {
seekingIterator.close();
}
}
@@ -90,7 +91,6 @@ private DbEntry adapt(Entry entry)
// todo Implement reverse iterator
//
-
@Override
public void seekToLast()
{
@@ -115,7 +115,8 @@ public DbEntry peekPrev()
throw new UnsupportedOperationException();
}
- public static class DbEntry implements Entry
+ public static class DbEntry
+ implements Entry
{
private final Slice key;
private final Slice value;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/SequenceNumber.java b/leveldb/src/main/java/org/iq80/leveldb/impl/SequenceNumber.java
index 9759e239..e67ce20d 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/SequenceNumber.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/SequenceNumber.java
@@ -25,6 +25,10 @@ public final class SequenceNumber
// can be packed together into 64-bits.
public static final long MAX_SEQUENCE_NUMBER = ((0x1L << 56) - 1);
+ private SequenceNumber()
+ {
+ }
+
public static long packSequenceAndValueType(long sequence, ValueType valueType)
{
Preconditions.checkArgument(sequence <= MAX_SEQUENCE_NUMBER, "Sequence number is greater than MAX_SEQUENCE_NUMBER");
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotImpl.java b/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotImpl.java
index 11d49d23..8e6fb368 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotImpl.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotImpl.java
@@ -21,7 +21,8 @@
import java.util.concurrent.atomic.AtomicBoolean;
-public class SnapshotImpl implements Snapshot
+public class SnapshotImpl
+ implements Snapshot
{
private final AtomicBoolean closed = new AtomicBoolean();
private final Version version;
@@ -39,39 +40,52 @@ public void close()
{
// This is an end user API.. he might screw up and close multiple times.
// but we don't want the version reference count going bad.
- if(closed.compareAndSet(false, true)) {
+ if (closed.compareAndSet(false, true)) {
this.version.release();
}
}
- public long getLastSequence() {
+ public long getLastSequence()
+ {
return lastSequence;
}
- public Version getVersion() {
+ public Version getVersion()
+ {
return version;
}
@Override
- public String toString() {
+ public String toString()
+ {
return Long.toString(lastSequence);
}
@Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ public boolean equals(Object o)
+ {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
SnapshotImpl snapshot = (SnapshotImpl) o;
- if (lastSequence != snapshot.lastSequence) return false;
- if (!version.equals(snapshot.version)) return false;
+ if (lastSequence != snapshot.lastSequence) {
+ return false;
+ }
+ if (!version.equals(snapshot.version)) {
+ return false;
+ }
return true;
}
@Override
- public int hashCode() {
+ public int hashCode()
+ {
int result = version.hashCode();
result = 31 * result + (int) (lastSequence ^ (lastSequence >>> 32));
return result;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotSeekingIterator.java b/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotSeekingIterator.java
index 2a4c6800..ba4649d7 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotSeekingIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotSeekingIterator.java
@@ -25,7 +25,8 @@
import java.util.Comparator;
import java.util.Map.Entry;
-public final class SnapshotSeekingIterator extends AbstractSeekingIterator
+public final class SnapshotSeekingIterator
+ extends AbstractSeekingIterator
{
private final DbIterator iterator;
private final SnapshotImpl snapshot;
@@ -39,7 +40,8 @@ public SnapshotSeekingIterator(DbIterator iterator, SnapshotImpl snapshot, Compa
this.snapshot.getVersion().retain();
}
- public void close() {
+ public void close()
+ {
this.snapshot.getVersion().release();
}
@@ -113,5 +115,4 @@ public String toString()
sb.append('}');
return sb.toString();
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/TableCache.java b/leveldb/src/main/java/org/iq80/leveldb/impl/TableCache.java
index 422a1a05..e00ade3f 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/TableCache.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/TableCache.java
@@ -23,11 +23,11 @@
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
-import org.iq80.leveldb.util.Closeables;
import org.iq80.leveldb.table.FileChannelTable;
import org.iq80.leveldb.table.MMapTable;
import org.iq80.leveldb.table.Table;
import org.iq80.leveldb.table.UserComparator;
+import org.iq80.leveldb.util.Closeables;
import org.iq80.leveldb.util.Finalizer;
import org.iq80.leveldb.util.InternalTableIterator;
import org.iq80.leveldb.util.Slice;
@@ -49,15 +49,19 @@ public TableCache(final File databaseDir, int tableCacheSize, final UserComparat
cache = CacheBuilder.newBuilder()
.maximumSize(tableCacheSize)
- .removalListener(new RemovalListener() {
- public void onRemoval(RemovalNotification notification) {
+ .removalListener(new RemovalListener()
+ {
+ public void onRemoval(RemovalNotification notification)
+ {
Table table = notification.getValue().getTable();
finalizer.addCleanup(table, table.closer());
}
})
- .build(new CacheLoader() {
+ .build(new CacheLoader()
+ {
public TableAndFile load(Long fileNumber)
- throws IOException {
+ throws IOException
+ {
return new TableAndFile(databaseDir, fileNumber, userComparator, verifyChecksums);
}
});
@@ -73,7 +77,8 @@ public InternalTableIterator newIterator(long number)
return new InternalTableIterator(getTable(number).iterator());
}
- public long getApproximateOffsetOf(FileMetaData file, Slice key) {
+ public long getApproximateOffsetOf(FileMetaData file, Slice key)
+ {
return getTable(file.getNumber()).getApproximateOffsetOf(key);
}
@@ -93,7 +98,8 @@ private Table getTable(long number)
return table;
}
- public void close() {
+ public void close()
+ {
cache.invalidateAll();
finalizer.destroy();
}
@@ -115,9 +121,10 @@ private TableAndFile(File databaseDir, long fileNumber, UserComparator userCompa
File tableFile = new File(databaseDir, tableFileName);
fileChannel = new FileInputStream(tableFile).getChannel();
try {
- if( Iq80DBFactory.USE_MMAP ) {
+ if (Iq80DBFactory.USE_MMAP) {
table = new MMapTable(tableFile.getAbsolutePath(), fileChannel, userComparator, verifyChecksums);
- } else {
+ }
+ else {
table = new FileChannelTable(tableFile.getAbsolutePath(), fileChannel, userComparator, verifyChecksums);
}
}
@@ -132,5 +139,4 @@ public Table getTable()
return table;
}
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/ValueType.java b/leveldb/src/main/java/org/iq80/leveldb/impl/ValueType.java
index 27a9156a..d03b14ce 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/ValueType.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/ValueType.java
@@ -22,7 +22,8 @@ public enum ValueType
DELETION(0x00),
VALUE(0x01);
- public static ValueType getValueTypeByPersistentId(int persistentId) {
+ public static ValueType getValueTypeByPersistentId(int persistentId)
+ {
switch (persistentId) {
case 0:
return DELETION;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/Version.java b/leveldb/src/main/java/org/iq80/leveldb/impl/Version.java
index 8068ad38..d3179530 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/Version.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/Version.java
@@ -23,7 +23,11 @@
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
-import org.iq80.leveldb.util.*;
+import org.iq80.leveldb.util.InternalIterator;
+import org.iq80.leveldb.util.InternalTableIterator;
+import org.iq80.leveldb.util.LevelIterator;
+import org.iq80.leveldb.util.MergingIterator;
+import org.iq80.leveldb.util.Slice;
import java.util.Collection;
import java.util.List;
@@ -37,7 +41,8 @@
import static org.iq80.leveldb.impl.VersionSet.MAX_GRAND_PARENT_OVERLAP_BYTES;
// todo this class should be immutable
-public class Version implements SeekingIterable
+public class Version
+ implements SeekingIterable
{
private final AtomicInteger retained = new AtomicInteger(1);
private final VersionSet versionSet;
@@ -95,7 +100,8 @@ public void assertNoOverlappingFiles(int level)
}
}
- private TableCache getTableCache() {
+ private TableCache getTableCache()
+ {
return versionSet.getTableCache();
}
@@ -125,7 +131,8 @@ public synchronized void setCompactionScore(double compactionScore)
}
@Override
- public MergingIterator iterator() {
+ public MergingIterator iterator()
+ {
Builder builder = ImmutableList.builder();
builder.add(level0.iterator());
builder.addAll(getLevelIterators());
@@ -199,7 +206,7 @@ public boolean overlapInLevel(int level, Slice smallestUserKey, Slice largestUse
Preconditions.checkNotNull(smallestUserKey, "smallestUserKey is null");
Preconditions.checkNotNull(largestUserKey, "largestUserKey is null");
- if (level == 0) {
+ if (level == 0) {
return level0.someFileOverlapsRange(smallestUserKey, largestUserKey);
}
return levels.get(level - 1).someFileOverlapsRange(smallestUserKey, largestUserKey);
@@ -214,7 +221,8 @@ public int numberOfFilesInLevel(int level)
{
if (level == 0) {
return level0.getFiles().size();
- } else {
+ }
+ else {
return levels.get(level - 1).getFiles().size();
}
}
@@ -236,7 +244,8 @@ public List getFiles(int level)
{
if (level == 0) {
return level0.getFiles();
- } else {
+ }
+ else {
return levels.get(level - 1).getFiles();
}
}
@@ -245,7 +254,8 @@ public void addFile(int level, FileMetaData fileMetaData)
{
if (level == 0) {
level0.addFile(fileMetaData);
- } else {
+ }
+ else {
levels.get(level - 1).addFile(fileMetaData);
}
}
@@ -303,23 +313,24 @@ else if (getInternalKeyComparator().compare(fileMetaData.getSmallest(), key) > 0
return result;
}
- public void retain() {
+ public void retain()
+ {
int was = retained.getAndIncrement();
- assert was>0 : "Version was retain after it was disposed.";
+ assert was > 0 : "Version was retain after it was disposed.";
}
- public void release() {
+ public void release()
+ {
int now = retained.decrementAndGet();
assert now >= 0 : "Version was released after it was disposed.";
- if( now == 0 ) {
+ if (now == 0) {
// The version is now disposed.
versionSet.removeVersion(this);
}
}
-
- public boolean isDisposed() {
+
+ public boolean isDisposed()
+ {
return retained.get() <= 0;
}
-
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/VersionEdit.java b/leveldb/src/main/java/org/iq80/leveldb/impl/VersionEdit.java
index de70bb5a..64d6c244 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/VersionEdit.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/VersionEdit.java
@@ -47,7 +47,7 @@ public VersionEdit()
public VersionEdit(Slice slice)
{
SliceInput sliceInput = slice.input();
- while(sliceInput.isReadable()) {
+ while (sliceInput.isReadable()) {
int i = VariableLengthQuantity.readVariableLengthInt(sliceInput);
VersionEditTag tag = VersionEditTag.getValueTypeByPersistentId(i);
tag.readValue(sliceInput, this);
@@ -132,7 +132,6 @@ public void addFile(int level, long fileNumber,
InternalKey smallest,
InternalKey largest)
{
-
FileMetaData fileMetaData = new FileMetaData(fileNumber, fileSize, smallest, largest);
addFile(level, fileMetaData);
}
@@ -147,7 +146,6 @@ public void addFiles(Multimap files)
newFiles.putAll(files);
}
-
public Multimap getDeletedFiles()
{
return ImmutableMultimap.copyOf(deletedFiles);
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/VersionEditTag.java b/leveldb/src/main/java/org/iq80/leveldb/impl/VersionEditTag.java
index 1eec95f6..f3927c7a 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/VersionEditTag.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/VersionEditTag.java
@@ -19,8 +19,8 @@
import com.google.common.base.Charsets;
import org.iq80.leveldb.util.SliceInput;
-import org.iq80.leveldb.util.VariableLengthQuantity;
import org.iq80.leveldb.util.SliceOutput;
+import org.iq80.leveldb.util.VariableLengthQuantity;
import java.util.Map.Entry;
@@ -29,6 +29,8 @@
public enum VersionEditTag
{
+ // 8 is no longer used. It was used for large value refs.
+
COMPARATOR(1)
{
@Override
@@ -218,7 +220,6 @@ public void writeValue(SliceOutput sliceOutput, VersionEdit versionEdit)
// level
VariableLengthQuantity.writeVariableLengthInt(entry.getKey(), sliceOutput);
-
// file number
FileMetaData fileMetaData = entry.getValue();
VariableLengthQuantity.writeVariableLengthLong(fileMetaData.getNumber(), sliceOutput);
@@ -233,9 +234,7 @@ public void writeValue(SliceOutput sliceOutput, VersionEdit versionEdit)
writeLengthPrefixedBytes(sliceOutput, fileMetaData.getLargest().encode());
}
}
- }
- // 8 was used for large value refs
- ;
+ };
public static VersionEditTag getValueTypeByPersistentId(int persistentId)
{
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/VersionSet.java b/leveldb/src/main/java/org/iq80/leveldb/impl/VersionSet.java
index b2ef9843..be43f36f 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/VersionSet.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/VersionSet.java
@@ -54,7 +54,8 @@
import static org.iq80.leveldb.impl.DbConstants.NUM_LEVELS;
import static org.iq80.leveldb.impl.LogMonitors.throwExceptionMonitor;
-public class VersionSet implements SeekingIterable
+public class VersionSet
+ implements SeekingIterable
{
private static final int L0_COMPACTION_TRIGGER = 4;
@@ -64,7 +65,6 @@ public class VersionSet implements SeekingIterable
// stop building a single file in a level.level+1 compaction.
public static final long MAX_GRAND_PARENT_OVERLAP_BYTES = 10 * TARGET_FILE_SIZE;
-
private final AtomicLong nextFileNumber = new AtomicLong(2);
private long manifestFileNumber = 1;
private Version current;
@@ -107,7 +107,8 @@ private void initializeIfNeeded()
try {
writeSnapshot(log);
log.addRecord(edit.encode(), false);
- } finally {
+ }
+ finally {
log.close();
}
@@ -122,9 +123,9 @@ public void destroy()
descriptorLog.close();
descriptorLog = null;
}
-
+
Version t = current;
- if( t!=null ) {
+ if (t != null) {
current = null;
t.release();
}
@@ -141,23 +142,26 @@ private void appendVersion(Version version)
Version previous = current;
current = version;
activeVersions.put(version, new Object());
- if(previous!=null) {
+ if (previous != null) {
previous.release();
}
}
- public void removeVersion(Version version) {
+ public void removeVersion(Version version)
+ {
Preconditions.checkNotNull(version, "version is null");
Preconditions.checkArgument(version != current, "version is the current version");
- boolean removed = activeVersions.remove(version)!=null;
+ boolean removed = activeVersions.remove(version) != null;
assert removed : "Expected the version to still be in the active set";
}
- public InternalKeyComparator getInternalKeyComparator() {
+ public InternalKeyComparator getInternalKeyComparator()
+ {
return internalKeyComparator;
}
- public TableCache getTableCache() {
+ public TableCache getTableCache()
+ {
return tableCache;
}
@@ -199,15 +203,16 @@ public MergingIterator makeInputIterator(Compaction c)
// TODO(opt): use concatenating iterator for level-0 if there is no overlap
List list = newArrayList();
for (int which = 0; which < 2; which++) {
- if (!c.getInputs()[which].isEmpty()) {
- if (c.getLevel() + which == 0) {
- List files = c.getInputs()[which];
- list.add(new Level0Iterator(tableCache, files, internalKeyComparator));
- } else {
- // Create concatenating iterator for the files from this level
- list.add(Level.createLevelConcatIterator(tableCache, c.getInputs()[which], internalKeyComparator));
+ if (!c.getInputs()[which].isEmpty()) {
+ if (c.getLevel() + which == 0) {
+ List files = c.getInputs()[which];
+ list.add(new Level0Iterator(tableCache, files, internalKeyComparator));
+ }
+ else {
+ // Create concatenating iterator for the files from this level
+ list.add(Level.createLevelConcatIterator(tableCache, c.getInputs()[which], internalKeyComparator));
+ }
}
- }
}
return new MergingIterator(list, internalKeyComparator);
}
@@ -326,7 +331,6 @@ private void writeSnapshot(LogWriter log)
public void recover()
throws IOException
{
-
// Read "CURRENT" file, which contains a pointer to the current manifest file
File currentFile = new File(databaseDir, Filename.currentFileName());
Preconditions.checkState(currentFile.exists(), "CURRENT file does not exist");
@@ -340,68 +344,68 @@ public void recover()
// open file channel
FileChannel fileChannel = new FileInputStream(new File(databaseDir, currentName)).getChannel();
try {
-
- // read log edit log
- Long nextFileNumber = null;
- Long lastSequence = null;
- Long logNumber = null;
- Long prevLogNumber = null;
- Builder builder = new Builder(this, current);
-
- LogReader reader = new LogReader(fileChannel, throwExceptionMonitor(), true, 0);
- for (Slice record = reader.readRecord(); record != null; record = reader.readRecord()) {
- // read version edit
- VersionEdit edit = new VersionEdit(record);
-
- // verify comparator
- // todo implement user comparator
- String editComparator = edit.getComparatorName();
- String userComparator = internalKeyComparator.name();
- Preconditions.checkArgument(editComparator == null || editComparator.equals(userComparator),
- "Expected user comparator %s to match existing database comparator ", userComparator, editComparator);
-
- // apply edit
- builder.apply(edit);
-
- // save edit values for verification below
- logNumber = coalesce(edit.getLogNumber(), logNumber);
- prevLogNumber = coalesce(edit.getPreviousLogNumber(), prevLogNumber);
- nextFileNumber = coalesce(edit.getNextFileNumber(), nextFileNumber);
- lastSequence = coalesce(edit.getLastSequenceNumber(), lastSequence);
- }
-
- List problems = newArrayList();
- if (nextFileNumber == null) {
- problems.add("Descriptor does not contain a meta-nextfile entry");
- }
- if (logNumber == null) {
- problems.add("Descriptor does not contain a meta-lognumber entry");
- }
- if (lastSequence == null) {
- problems.add("Descriptor does not contain a last-sequence-number entry");
- }
- if (!problems.isEmpty()) {
- throw new RuntimeException("Corruption: \n\t" + Joiner.on("\n\t").join(problems));
- }
-
- if (prevLogNumber == null) {
- prevLogNumber = 0L;
- }
-
- Version newVersion = new Version(this);
- builder.saveTo(newVersion);
-
- // Install recovered version
- finalizeVersion(newVersion);
-
- appendVersion(newVersion);
- manifestFileNumber = nextFileNumber;
- this.nextFileNumber.set(nextFileNumber + 1);
- this.lastSequence = lastSequence;
- this.logNumber = logNumber;
- this.prevLogNumber = prevLogNumber;
- } finally {
- fileChannel.close();
+ // read log edit log
+ Long nextFileNumber = null;
+ Long lastSequence = null;
+ Long logNumber = null;
+ Long prevLogNumber = null;
+ Builder builder = new Builder(this, current);
+
+ LogReader reader = new LogReader(fileChannel, throwExceptionMonitor(), true, 0);
+ for (Slice record = reader.readRecord(); record != null; record = reader.readRecord()) {
+ // read version edit
+ VersionEdit edit = new VersionEdit(record);
+
+ // verify comparator
+ // todo implement user comparator
+ String editComparator = edit.getComparatorName();
+ String userComparator = internalKeyComparator.name();
+ Preconditions.checkArgument(editComparator == null || editComparator.equals(userComparator),
+ "Expected user comparator %s to match existing database comparator ", userComparator, editComparator);
+
+ // apply edit
+ builder.apply(edit);
+
+ // save edit values for verification below
+ logNumber = coalesce(edit.getLogNumber(), logNumber);
+ prevLogNumber = coalesce(edit.getPreviousLogNumber(), prevLogNumber);
+ nextFileNumber = coalesce(edit.getNextFileNumber(), nextFileNumber);
+ lastSequence = coalesce(edit.getLastSequenceNumber(), lastSequence);
+ }
+
+ List problems = newArrayList();
+ if (nextFileNumber == null) {
+ problems.add("Descriptor does not contain a meta-nextfile entry");
+ }
+ if (logNumber == null) {
+ problems.add("Descriptor does not contain a meta-lognumber entry");
+ }
+ if (lastSequence == null) {
+ problems.add("Descriptor does not contain a last-sequence-number entry");
+ }
+ if (!problems.isEmpty()) {
+ throw new RuntimeException("Corruption: \n\t" + Joiner.on("\n\t").join(problems));
+ }
+
+ if (prevLogNumber == null) {
+ prevLogNumber = 0L;
+ }
+
+ Version newVersion = new Version(this);
+ builder.saveTo(newVersion);
+
+ // Install recovered version
+ finalizeVersion(newVersion);
+
+ appendVersion(newVersion);
+ manifestFileNumber = nextFileNumber;
+ this.nextFileNumber.set(nextFileNumber + 1);
+ this.lastSequence = lastSequence;
+ this.logNumber = logNumber;
+ this.prevLogNumber = prevLogNumber;
+ }
+ finally {
+ fileChannel.close();
}
}
@@ -465,7 +469,6 @@ public List getLiveFiles()
return builder.build();
}
-
private static double maxBytesForLevel(int level)
{
// Note: the result for level zero is not really used since we set
@@ -565,7 +568,6 @@ private Compaction setupOtherInputs(int level, List levelInputs)
// See if we can grow the number of inputs in "level" without
// changing the number of "level+1" files we pick up.
if (!levelUpInputs.isEmpty()) {
-
List expanded0 = getOverlappingInputs(level, allStart, allLimit);
if (expanded0.size() > levelInputs.size()) {
@@ -590,7 +592,6 @@ private Compaction setupOtherInputs(int level, List levelInputs)
range = getRange(levelInputs, levelUpInputs);
allStart = range.getKey();
allLimit = range.getValue();
-
}
}
}
@@ -757,7 +758,6 @@ public void saveTo(Version version)
{
FileMetaDataBySmallestKey cmp = new FileMetaDataBySmallestKey(versionSet.internalKeyComparator);
for (int level = 0; level < baseVersion.numberOfLevels(); level++) {
-
// Merge the set of added files with the set of pre-existing files.
// Drop any deleted files. Store the result in *v.
@@ -797,7 +797,7 @@ private void maybeAddFile(Version version, int level, FileMetaData fileMetaData)
List files = version.getFiles(level);
if (level > 0 && !files.isEmpty()) {
// Must not overlap
- boolean filesOverlap = versionSet.internalKeyComparator.compare(files.get(files.size() - 1).getLargest(), fileMetaData.getSmallest()) >= 0;
+ boolean filesOverlap = versionSet.internalKeyComparator.compare(files.get(files.size() - 1).getLargest(), fileMetaData.getSmallest()) >= 0;
if (filesOverlap) {
// A memory compaction, while this compaction was running, resulted in a a database state that is
// incompatible with the compaction. This is rare and expensive to detect while the compaction is
@@ -811,7 +811,8 @@ private void maybeAddFile(Version version, int level, FileMetaData fileMetaData)
}
}
- private static class FileMetaDataBySmallestKey implements Comparator
+ private static class FileMetaDataBySmallestKey
+ implements Comparator
{
private final InternalKeyComparator internalKeyComparator;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/impl/WriteBatchImpl.java b/leveldb/src/main/java/org/iq80/leveldb/impl/WriteBatchImpl.java
index d959944c..74885210 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/impl/WriteBatchImpl.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/impl/WriteBatchImpl.java
@@ -28,7 +28,8 @@
import static com.google.common.collect.Lists.newArrayList;
-public class WriteBatchImpl implements WriteBatch
+public class WriteBatchImpl
+ implements WriteBatch
{
private List> batch = newArrayList();
private int approximateSize;
@@ -104,5 +105,4 @@ public static interface Handler
void delete(Slice key);
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/Block.java b/leveldb/src/main/java/org/iq80/leveldb/table/Block.java
index a04eb990..f486bef0 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/Block.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/Block.java
@@ -60,7 +60,8 @@
*
*
*/
-public class Block implements SeekingIterable
+public class Block
+ implements SeekingIterable
{
private final Slice block;
private final Comparator comparator;
@@ -110,5 +111,4 @@ public BlockIterator iterator()
{
return new BlockIterator(data, restartPositions, comparator);
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/BlockEntry.java b/leveldb/src/main/java/org/iq80/leveldb/table/BlockEntry.java
index 22bbcd43..be6c2c07 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/BlockEntry.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/BlockEntry.java
@@ -21,7 +21,6 @@
import com.google.common.base.Preconditions;
import org.iq80.leveldb.util.Slice;
-import java.util.Arrays;
import java.util.Map.Entry;
import static com.google.common.base.Charsets.UTF_8;
@@ -72,7 +71,8 @@
*
*
*/
-public class BlockEntry implements Entry
+public class BlockEntry
+ implements Entry
{
public static final Function GET_KEY = new Function()
{
@@ -104,7 +104,6 @@ public Slice getValue()
return value;
}
-
/**
* @throws UnsupportedOperationException always
*/
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/BlockHandle.java b/leveldb/src/main/java/org/iq80/leveldb/table/BlockHandle.java
index e3fb8709..1f6e89c1 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/BlockHandle.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/BlockHandle.java
@@ -19,9 +19,9 @@
import org.iq80.leveldb.util.Slice;
import org.iq80.leveldb.util.SliceInput;
+import org.iq80.leveldb.util.SliceOutput;
import org.iq80.leveldb.util.Slices;
import org.iq80.leveldb.util.VariableLengthQuantity;
-import org.iq80.leveldb.util.SliceOutput;
public class BlockHandle
{
@@ -46,7 +46,8 @@ public int getDataSize()
return dataSize;
}
- public int getFullBlockSize() {
+ public int getFullBlockSize()
+ {
return dataSize + BlockTrailer.ENCODED_LENGTH;
}
@@ -110,6 +111,7 @@ public static Slice writeBlockHandle(BlockHandle blockHandle)
writeBlockHandleTo(blockHandle, sliceOutput);
return slice.slice();
}
+
public static void writeBlockHandleTo(BlockHandle blockHandle, SliceOutput sliceOutput)
{
VariableLengthQuantity.writeVariableLengthLong(blockHandle.offset, sliceOutput);
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/BlockIterator.java b/leveldb/src/main/java/org/iq80/leveldb/table/BlockIterator.java
index 1d5e8e9e..3eb4d73b 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/BlockIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/BlockIterator.java
@@ -19,18 +19,19 @@
import com.google.common.base.Preconditions;
import org.iq80.leveldb.impl.SeekingIterator;
-import org.iq80.leveldb.util.SliceInput;
import org.iq80.leveldb.util.Slice;
+import org.iq80.leveldb.util.SliceInput;
+import org.iq80.leveldb.util.SliceOutput;
import org.iq80.leveldb.util.Slices;
import org.iq80.leveldb.util.VariableLengthQuantity;
-import org.iq80.leveldb.util.SliceOutput;
import java.util.Comparator;
import java.util.NoSuchElementException;
import static org.iq80.leveldb.util.SizeOf.SIZE_OF_INT;
-public class BlockIterator implements SeekingIterator
+public class BlockIterator
+ implements SeekingIterator
{
private final SliceInput data;
private final Slice restartPositions;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/BlockTrailer.java b/leveldb/src/main/java/org/iq80/leveldb/table/BlockTrailer.java
index d05995ff..3a329fa5 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/BlockTrailer.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/BlockTrailer.java
@@ -19,10 +19,10 @@
import com.google.common.base.Preconditions;
import org.iq80.leveldb.CompressionType;
-import org.iq80.leveldb.util.SliceInput;
import org.iq80.leveldb.util.Slice;
-import org.iq80.leveldb.util.Slices;
+import org.iq80.leveldb.util.SliceInput;
import org.iq80.leveldb.util.SliceOutput;
+import org.iq80.leveldb.util.Slices;
public class BlockTrailer
{
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/BytewiseComparator.java b/leveldb/src/main/java/org/iq80/leveldb/table/BytewiseComparator.java
index 295a0774..8625d3fe 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/BytewiseComparator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/BytewiseComparator.java
@@ -19,11 +19,12 @@
import org.iq80.leveldb.util.Slice;
-public class BytewiseComparator implements UserComparator
+public class BytewiseComparator
+ implements UserComparator
{
-
@Override
- public String name() {
+ public String name()
+ {
return "leveldb.BytewiseComparator";
}
@@ -65,7 +66,7 @@ public Slice findShortSuccessor(Slice key)
int b = key.getUnsignedByte(i);
if (b != 0xff) {
Slice result = key.copySlice(0, i + 1);
- result.setByte(i, b +1);
+ result.setByte(i, b + 1);
return result;
}
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/CustomUserComparator.java b/leveldb/src/main/java/org/iq80/leveldb/table/CustomUserComparator.java
index d4ccb386..756280c2 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/CustomUserComparator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/CustomUserComparator.java
@@ -31,22 +31,26 @@ public CustomUserComparator(DBComparator comparator)
}
@Override
- public String name() {
+ public String name()
+ {
return comparator.name();
}
@Override
- public Slice findShortestSeparator(Slice start, Slice limit) {
+ public Slice findShortestSeparator(Slice start, Slice limit)
+ {
return new Slice(comparator.findShortestSeparator(start.getBytes(), limit.getBytes()));
}
@Override
- public Slice findShortSuccessor(Slice key) {
+ public Slice findShortSuccessor(Slice key)
+ {
return new Slice(comparator.findShortSuccessor(key.getBytes()));
}
@Override
- public int compare(Slice o1, Slice o2) {
+ public int compare(Slice o1, Slice o2)
+ {
return comparator.compare(o1.getBytes(), o2.getBytes());
}
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/FileChannelTable.java b/leveldb/src/main/java/org/iq80/leveldb/table/FileChannelTable.java
index bb0dbdca..8c4a97b7 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/FileChannelTable.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/FileChannelTable.java
@@ -17,7 +17,9 @@
*/
package org.iq80.leveldb.table;
-import org.iq80.leveldb.util.*;
+import org.iq80.leveldb.util.Slice;
+import org.iq80.leveldb.util.Slices;
+import org.iq80.leveldb.util.Snappy;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -26,7 +28,8 @@
import static org.iq80.leveldb.CompressionType.SNAPPY;
-public class FileChannelTable extends Table
+public class FileChannelTable
+ extends Table
{
public FileChannelTable(String name, FileChannel fileChannel, Comparator comparator, boolean verifyChecksums)
throws IOException
@@ -35,7 +38,9 @@ public FileChannelTable(String name, FileChannel fileChannel, Comparator
}
@Override
- protected Footer init() throws IOException {
+ protected Footer init()
+ throws IOException
+ {
long size = fileChannel.size();
ByteBuffer footerData = read(size - Footer.ENCODED_LENGTH, Footer.ENCODED_LENGTH);
return Footer.readFooter(Slices.copiedBuffer(footerData));
@@ -82,15 +87,15 @@ protected Block readBlock(BlockHandle blockHandle)
return new Block(uncompressedData, comparator);
}
- private ByteBuffer read(long offset, int length) throws IOException {
+ private ByteBuffer read(long offset, int length)
+ throws IOException
+ {
ByteBuffer uncompressedBuffer = ByteBuffer.allocate(length);
fileChannel.read(uncompressedBuffer, offset);
- if( uncompressedBuffer.hasRemaining() ) {
+ if (uncompressedBuffer.hasRemaining()) {
throw new IOException("Could not read all the data");
}
uncompressedBuffer.clear();
return uncompressedBuffer;
}
-
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/Footer.java b/leveldb/src/main/java/org/iq80/leveldb/table/Footer.java
index 5d9a626e..d8bd0f4b 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/Footer.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/Footer.java
@@ -20,8 +20,8 @@
import com.google.common.base.Preconditions;
import org.iq80.leveldb.util.Slice;
import org.iq80.leveldb.util.SliceInput;
-import org.iq80.leveldb.util.Slices;
import org.iq80.leveldb.util.SliceOutput;
+import org.iq80.leveldb.util.Slices;
import static org.iq80.leveldb.table.BlockHandle.readBlockHandle;
import static org.iq80.leveldb.table.BlockHandle.writeBlockHandleTo;
@@ -71,10 +71,10 @@ public static Footer readFooter(Slice slice)
return new Footer(metaindexBlockHandle, indexBlockHandle);
}
- public static Slice writeFooter(Footer Footer)
+ public static Slice writeFooter(Footer footer)
{
Slice slice = Slices.allocate(ENCODED_LENGTH);
- writeFooter(Footer, slice.output());
+ writeFooter(footer, slice.output());
return slice;
}
@@ -94,5 +94,4 @@ public static void writeFooter(Footer footer, SliceOutput sliceOutput)
sliceOutput.writeInt((int) TableBuilder.TABLE_MAGIC_NUMBER);
sliceOutput.writeInt((int) (TableBuilder.TABLE_MAGIC_NUMBER >>> 32));
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/MMapTable.java b/leveldb/src/main/java/org/iq80/leveldb/table/MMapTable.java
index 44e25013..90c6aadb 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/table/MMapTable.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/MMapTable.java
@@ -36,7 +36,8 @@
import static org.iq80.leveldb.CompressionType.SNAPPY;
-public class MMapTable extends Table
+public class MMapTable
+ extends Table
{
private final AtomicBoolean closed = new AtomicBoolean(false);
private MappedByteBuffer data;
@@ -48,7 +49,9 @@ public MMapTable(String name, FileChannel fileChannel, Comparator compara
}
@Override
- protected Footer init() throws IOException {
+ protected Footer init()
+ throws IOException
+ {
long size = fileChannel.size();
data = fileChannel.map(MapMode.READ_ONLY, 0, size);
Slice footerSlice = Slices.copiedBuffer(data, (int) size - Footer.ENCODED_LENGTH, Footer.ENCODED_LENGTH);
@@ -56,11 +59,13 @@ protected Footer init() throws IOException {
}
@Override
- public Callable> closer() {
+ public Callable> closer()
+ {
return new Closer(name, fileChannel, data);
}
- private static class Closer implements Callable
+ private static class Closer
+ implements Callable
{
private final String name;
private final Closeable closeable;
@@ -81,7 +86,6 @@ public Void call()
}
}
-
@Override
protected Block readBlock(BlockHandle blockHandle)
throws IOException
@@ -131,5 +135,4 @@ public static ByteBuffer read(MappedByteBuffer data, int offset, int length)
ByteBuffer block = (ByteBuffer) data.duplicate().order(ByteOrder.LITTLE_ENDIAN).clear().limit(newPosition + length).position(newPosition);
return block;
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/Table.java b/leveldb/src/main/java/org/iq80/leveldb/table/Table.java
index eaf9d3af..aefb265f 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/table/Table.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/Table.java
@@ -32,7 +32,8 @@
import java.util.Comparator;
import java.util.concurrent.Callable;
-abstract public class Table implements SeekingIterable
+public abstract class Table
+ implements SeekingIterable
{
protected final String name;
protected final FileChannel fileChannel;
@@ -61,7 +62,8 @@ public Table(String name, FileChannel fileChannel, Comparator comparator,
metaindexBlockHandle = footer.getMetaindexBlockHandle();
}
- abstract protected Footer init() throws IOException;
+ protected abstract Footer init()
+ throws IOException;
@Override
public TableIterator iterator()
@@ -84,7 +86,7 @@ public Block openBlock(Slice blockEntry)
protected static ByteBuffer uncompressedScratch = ByteBuffer.allocateDirect(4 * 1024 * 1024);
- abstract protected Block readBlock(BlockHandle blockHandle)
+ protected abstract Block readBlock(BlockHandle blockHandle)
throws IOException;
protected int uncompressedLength(ByteBuffer data)
@@ -117,7 +119,6 @@ public long getApproximateOffsetOf(Slice key)
return metaindexBlockHandle.getOffset();
}
-
@Override
public String toString()
{
@@ -130,11 +131,13 @@ public String toString()
return sb.toString();
}
- public Callable> closer() {
+ public Callable> closer()
+ {
return new Closer(fileChannel);
}
- private static class Closer implements Callable
+ private static class Closer
+ implements Callable
{
private final Closeable closeable;
@@ -149,5 +152,4 @@ public Void call()
return null;
}
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/TableBuilder.java b/leveldb/src/main/java/org/iq80/leveldb/table/TableBuilder.java
index 0b0ea946..13d1ebc3 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/TableBuilder.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/TableBuilder.java
@@ -195,7 +195,7 @@ private BlockHandle writeBlock(BlockBuilder blockBuilder)
BlockHandle blockHandle = new BlockHandle(position, blockContents.length());
// write data and trailer
- position += fileChannel.write(new ByteBuffer[]{blockContents.toByteBuffer(), trailer.toByteBuffer()});
+ position += fileChannel.write(new ByteBuffer[] {blockContents.toByteBuffer(), trailer.toByteBuffer()});
// clean up state
blockBuilder.reset();
diff --git a/leveldb/src/main/java/org/iq80/leveldb/table/UserComparator.java b/leveldb/src/main/java/org/iq80/leveldb/table/UserComparator.java
index 289e0f95..d6557a6e 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/table/UserComparator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/table/UserComparator.java
@@ -22,7 +22,8 @@
import java.util.Comparator;
// todo this interface needs more thought
-public interface UserComparator extends Comparator
+public interface UserComparator
+ extends Comparator
{
String name();
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/AbstractSeekingIterator.java b/leveldb/src/main/java/org/iq80/leveldb/util/AbstractSeekingIterator.java
index 79a1294a..5e20ac84 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/AbstractSeekingIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/AbstractSeekingIterator.java
@@ -22,7 +22,8 @@
import java.util.Map.Entry;
import java.util.NoSuchElementException;
-public abstract class AbstractSeekingIterator implements SeekingIterator
+public abstract class AbstractSeekingIterator
+ implements SeekingIterator
{
private Entry nextElement;
@@ -84,6 +85,8 @@ public final void remove()
}
protected abstract void seekToFirstInternal();
+
protected abstract void seekInternal(K targetKey);
+
protected abstract Entry getNextElement();
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/BasicSliceOutput.java b/leveldb/src/main/java/org/iq80/leveldb/util/BasicSliceOutput.java
index 5ab62ab8..4149ff4e 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/BasicSliceOutput.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/BasicSliceOutput.java
@@ -24,7 +24,8 @@
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
-public class BasicSliceOutput extends SliceOutput
+public class BasicSliceOutput
+ extends SliceOutput
{
private final Slice slice;
private int size;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/ByteBufferSupport.java b/leveldb/src/main/java/org/iq80/leveldb/util/ByteBufferSupport.java
index b26be7c9..b5359fc7 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/util/ByteBufferSupport.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/ByteBufferSupport.java
@@ -1,54 +1,55 @@
-/*
- * Copyright (C) 2011 the original author or authors.
- * See the notice.md file distributed with this work for additional
- * information regarding copyright ownership.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.iq80.leveldb.util;
-
-import com.google.common.base.Throwables;
-import sun.nio.ch.FileChannelImpl;
-
-import java.lang.reflect.Method;
-import java.nio.MappedByteBuffer;
-
-/**
- */
-public class ByteBufferSupport {
-
- private static final Method unmap;
- static {
- Method x;
- try {
- x = FileChannelImpl.class.getDeclaredMethod("unmap", MappedByteBuffer.class);
- }
- catch (NoSuchMethodException e) {
- throw new AssertionError(e);
- }
- x.setAccessible(true);
- unmap = x;
- }
-
- public static void unmap(MappedByteBuffer buffer)
- {
- try {
- unmap.invoke(null, buffer);
- }
- catch (Exception ignored) {
- throw Throwables.propagate(ignored);
- }
- }
-
-
-}
+/*
+ * Copyright (C) 2011 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.iq80.leveldb.util;
+
+import com.google.common.base.Throwables;
+import sun.nio.ch.FileChannelImpl;
+
+import java.lang.reflect.Method;
+import java.nio.MappedByteBuffer;
+
+public final class ByteBufferSupport
+{
+ private static final Method unmap;
+
+ static {
+ Method x;
+ try {
+ x = FileChannelImpl.class.getDeclaredMethod("unmap", MappedByteBuffer.class);
+ }
+ catch (NoSuchMethodException e) {
+ throw new AssertionError(e);
+ }
+ x.setAccessible(true);
+ unmap = x;
+ }
+
+ private ByteBufferSupport()
+ {
+ }
+
+ public static void unmap(MappedByteBuffer buffer)
+ {
+ try {
+ unmap.invoke(null, buffer);
+ }
+ catch (Exception ignored) {
+ throw Throwables.propagate(ignored);
+ }
+ }
+}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/Closeables.java b/leveldb/src/main/java/org/iq80/leveldb/util/Closeables.java
index 1a4d56e0..e5a0481f 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/Closeables.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/Closeables.java
@@ -22,7 +22,9 @@
public final class Closeables
{
- private Closeables() {}
+ private Closeables()
+ {
+ }
public static void closeQuietly(Closeable closeable)
{
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/DbIterator.java b/leveldb/src/main/java/org/iq80/leveldb/util/DbIterator.java
index b4620337..0af990fa 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/DbIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/DbIterator.java
@@ -29,9 +29,10 @@
import java.util.Map.Entry;
import java.util.NoSuchElementException;
-public final class DbIterator extends AbstractSeekingIterator implements InternalIterator
+public final class DbIterator
+ extends AbstractSeekingIterator
+ implements InternalIterator
{
-
/*
* NOTE: This code has been specifically tuned for performance of the DB
* iterator methods. Before committing changes to this code, make sure
@@ -48,7 +49,6 @@ public final class DbIterator extends AbstractSeekingIterator level0Files;
@@ -220,7 +220,8 @@ public String toString()
return sb.toString();
}
- private static class ComparableIterator implements Iterator>, Comparable
+ private static class ComparableIterator
+ implements Iterator>, Comparable
{
private final SeekingIterator iterator;
private final Comparator comparator;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/DynamicSliceOutput.java b/leveldb/src/main/java/org/iq80/leveldb/util/DynamicSliceOutput.java
index f50196b2..ae2b49ef 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/DynamicSliceOutput.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/DynamicSliceOutput.java
@@ -24,7 +24,8 @@
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
-public class DynamicSliceOutput extends SliceOutput
+public class DynamicSliceOutput
+ extends SliceOutput
{
private Slice slice;
private int size;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/FileUtils.java b/leveldb/src/main/java/org/iq80/leveldb/util/FileUtils.java
index 790f3bd2..26b01053 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/FileUtils.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/FileUtils.java
@@ -25,10 +25,14 @@
import java.io.FilenameFilter;
import java.io.IOException;
-public class FileUtils
+public final class FileUtils
{
private static final int TEMP_DIR_ATTEMPTS = 10000;
+ private FileUtils()
+ {
+ }
+
public static boolean isSymbolicLink(File file)
{
try {
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/Finalizer.java b/leveldb/src/main/java/org/iq80/leveldb/util/Finalizer.java
index 514460cd..f3e517a0 100755
--- a/leveldb/src/main/java/org/iq80/leveldb/util/Finalizer.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/Finalizer.java
@@ -22,7 +22,11 @@
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
-import java.util.concurrent.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicBoolean;
public class Finalizer
@@ -86,17 +90,18 @@ public synchronized void addCleanup(T item, Callable> cleanup)
// is no longer reachable (if the reference object is garbage collected we are never notified)
references.put(reference, Boolean.TRUE);
}
-
+
public synchronized void destroy()
{
destroyed = true;
- if( executor!=null ) {
+ if (executor != null) {
executor.shutdownNow();
}
- for(FinalizerPhantomReference r: references.keySet() ) {
+ for (FinalizerPhantomReference r : references.keySet()) {
try {
r.cleanup();
- } catch (Exception e) {
+ }
+ catch (Exception e) {
}
}
}
@@ -106,7 +111,8 @@ public interface FinalizerMonitor
void unexpectedException(Throwable throwable);
}
- private static class FinalizerPhantomReference extends PhantomReference
+ private static class FinalizerPhantomReference
+ extends PhantomReference
{
private final AtomicBoolean cleaned = new AtomicBoolean(false);
private final Callable> cleanup;
@@ -117,14 +123,17 @@ private FinalizerPhantomReference(T referent, ReferenceQueue super T> queue, C
this.cleanup = cleanup;
}
- private void cleanup() throws Exception {
- if(cleaned.compareAndSet(false, true)) {
+ private void cleanup()
+ throws Exception
+ {
+ if (cleaned.compareAndSet(false, true)) {
cleanup.call();
}
}
}
- private class FinalizerQueueProcessor implements Runnable
+ private class FinalizerQueueProcessor
+ implements Runnable
{
@Override
public void run()
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/IntVector.java b/leveldb/src/main/java/org/iq80/leveldb/util/IntVector.java
index 394f8191..78438500 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/IntVector.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/IntVector.java
@@ -56,7 +56,6 @@ private void ensureCapacity(int minCapacity)
return;
}
-
int newLength = values.length;
if (newLength == 0) {
newLength = 1;
@@ -73,7 +72,8 @@ public int[] values()
return Arrays.copyOf(values, size);
}
- public void write(SliceOutput sliceOutput) {
+ public void write(SliceOutput sliceOutput)
+ {
for (int index = 0; index < size; index++) {
sliceOutput.writeInt(values[index]);
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/InternalIterator.java b/leveldb/src/main/java/org/iq80/leveldb/util/InternalIterator.java
index 563fd5c7..e9f18f1e 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/InternalIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/InternalIterator.java
@@ -25,5 +25,7 @@
*
* @author Hiram Chirino
*/
-public interface InternalIterator extends SeekingIterator {
+public interface InternalIterator
+ extends SeekingIterator
+{
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/InternalTableIterator.java b/leveldb/src/main/java/org/iq80/leveldb/util/InternalTableIterator.java
index 2e93bd30..411c2ebc 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/InternalTableIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/InternalTableIterator.java
@@ -22,7 +22,9 @@
import java.util.Map.Entry;
-public class InternalTableIterator extends AbstractSeekingIterator implements InternalIterator
+public class InternalTableIterator
+ extends AbstractSeekingIterator
+ implements InternalIterator
{
private final TableIterator tableIterator;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/Level0Iterator.java b/leveldb/src/main/java/org/iq80/leveldb/util/Level0Iterator.java
index 07c4d56d..62c6e2b6 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/Level0Iterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/Level0Iterator.java
@@ -33,7 +33,9 @@
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
-public final class Level0Iterator extends AbstractSeekingIterator implements InternalIterator
+public final class Level0Iterator
+ extends AbstractSeekingIterator
+ implements InternalIterator
{
private final List inputs;
private final PriorityQueue priorityQueue;
@@ -114,11 +116,13 @@ public String toString()
return sb.toString();
}
- private static class ComparableIterator implements Iterator>, Comparable {
+ private static class ComparableIterator
+ implements Iterator>, Comparable
+ {
private final SeekingIterator iterator;
private final Comparator comparator;
private final int ordinal;
- private Entry nextElement;
+ private Entry nextElement;
private ComparableIterator(SeekingIterator iterator, Comparator comparator, int ordinal, Entry nextElement)
{
@@ -143,7 +147,8 @@ public Entry next()
Entry result = nextElement;
if (iterator.hasNext()) {
nextElement = iterator.next();
- } else {
+ }
+ else {
nextElement = null;
}
return result;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/LevelIterator.java b/leveldb/src/main/java/org/iq80/leveldb/util/LevelIterator.java
index 01ca318f..d29761ae 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/LevelIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/LevelIterator.java
@@ -25,7 +25,9 @@
import java.util.List;
import java.util.Map.Entry;
-public final class LevelIterator extends AbstractSeekingIterator implements InternalIterator
+public final class LevelIterator
+ extends AbstractSeekingIterator
+ implements InternalIterator
{
private final TableCache tableCache;
private final List files;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/MergingIterator.java b/leveldb/src/main/java/org/iq80/leveldb/util/MergingIterator.java
index b6c21002..33872b69 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/MergingIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/MergingIterator.java
@@ -20,10 +20,15 @@
import com.google.common.primitives.Ints;
import org.iq80.leveldb.impl.InternalKey;
-import java.util.*;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map.Entry;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
-public final class MergingIterator extends AbstractSeekingIterator
+public final class MergingIterator
+ extends AbstractSeekingIterator
{
private final List extends InternalIterator> levels;
private final PriorityQueue priorityQueue;
@@ -91,7 +96,8 @@ public String toString()
return sb.toString();
}
- private static class ComparableIterator implements Iterator>, Comparable
+ private static class ComparableIterator
+ implements Iterator>, Comparable
{
private final InternalIterator iterator;
private final Comparator comparator;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/PureJavaCrc32C.java b/leveldb/src/main/java/org/iq80/leveldb/util/PureJavaCrc32C.java
index bd0711cf..4ff5bdad 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/PureJavaCrc32C.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/PureJavaCrc32C.java
@@ -19,7 +19,6 @@
import java.util.zip.Checksum;
-
/**
* A pure-java implementation of the CRC32 checksum that uses
* the CRC32-C polynomial, the same polynomial used by iSCSI
@@ -27,7 +26,8 @@
*/
// this code was taken from Apache Hadoop
// todo modify to work on buffers directly to avoid extra memcopy
-public class PureJavaCrc32C implements Checksum
+public class PureJavaCrc32C
+ implements Checksum
{
private static final int MASK_DELTA = 0xa282ead8;
@@ -92,9 +92,12 @@ public void update(byte[] b, int off, int len)
int localCrc = crc;
while (len > 7) {
int c0 = b[off++] ^ localCrc;
- int c1 = b[off++] ^ (localCrc >>>= 8);
- int c2 = b[off++] ^ (localCrc >>>= 8);
- int c3 = b[off++] ^ (localCrc >>>= 8);
+ localCrc >>>= 8;
+ int c1 = b[off++] ^ (localCrc);
+ localCrc >>>= 8;
+ int c2 = b[off++] ^ (localCrc);
+ localCrc >>>= 8;
+ int c3 = b[off++] ^ (localCrc);
localCrc = (T8_7[c0 & 0xff] ^ T8_6[c1 & 0xff])
^ (T8_5[c2 & 0xff] ^ T8_4[c3 & 0xff]);
@@ -121,7 +124,7 @@ public void update(int b)
// java -cp build/test/classes/:build/classes/ \
// org.apache.hadoop.util.TestPureJavaCrc32\$Table 82F63B78
- static final int[] T8_0 = new int[]{
+ static final int[] T8_0 = new int[] {
0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4,
0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB,
0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B,
@@ -187,7 +190,7 @@ public void update(int b)
0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E,
0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351
};
- static final int[] T8_1 = new int[]{
+ static final int[] T8_1 = new int[] {
0x00000000, 0x13A29877, 0x274530EE, 0x34E7A899,
0x4E8A61DC, 0x5D28F9AB, 0x69CF5132, 0x7A6DC945,
0x9D14C3B8, 0x8EB65BCF, 0xBA51F356, 0xA9F36B21,
@@ -253,7 +256,7 @@ public void update(int b)
0xD98EEDC6, 0xCA2C75B1, 0xFECBDD28, 0xED69455F,
0x97048C1A, 0x84A6146D, 0xB041BCF4, 0xA3E32483
};
- static final int[] T8_2 = new int[]{
+ static final int[] T8_2 = new int[] {
0x00000000, 0xA541927E, 0x4F6F520D, 0xEA2EC073,
0x9EDEA41A, 0x3B9F3664, 0xD1B1F617, 0x74F06469,
0x38513EC5, 0x9D10ACBB, 0x773E6CC8, 0xD27FFEB6,
@@ -319,7 +322,7 @@ public void update(int b)
0xE5F54FC1, 0x40B4DDBF, 0xAA9A1DCC, 0x0FDB8FB2,
0x7B2BEBDB, 0xDE6A79A5, 0x3444B9D6, 0x91052BA8
};
- static final int[] T8_3 = new int[]{
+ static final int[] T8_3 = new int[] {
0x00000000, 0xDD45AAB8, 0xBF672381, 0x62228939,
0x7B2231F3, 0xA6679B4B, 0xC4451272, 0x1900B8CA,
0xF64463E6, 0x2B01C95E, 0x49234067, 0x9466EADF,
@@ -385,7 +388,7 @@ public void update(int b)
0x31035088, 0xEC46FA30, 0x8E647309, 0x5321D9B1,
0x4A21617B, 0x9764CBC3, 0xF54642FA, 0x2803E842
};
- static final int[] T8_4 = new int[]{
+ static final int[] T8_4 = new int[] {
0x00000000, 0x38116FAC, 0x7022DF58, 0x4833B0F4,
0xE045BEB0, 0xD854D11C, 0x906761E8, 0xA8760E44,
0xC5670B91, 0xFD76643D, 0xB545D4C9, 0x8D54BB65,
@@ -451,7 +454,7 @@ public void update(int b)
0x081E60E7, 0x300F0F4B, 0x783CBFBF, 0x402DD013,
0xE85BDE57, 0xD04AB1FB, 0x9879010F, 0xA0686EA3
};
- static final int[] T8_5 = new int[]{
+ static final int[] T8_5 = new int[] {
0x00000000, 0xEF306B19, 0xDB8CA0C3, 0x34BCCBDA,
0xB2F53777, 0x5DC55C6E, 0x697997B4, 0x8649FCAD,
0x6006181F, 0x8F367306, 0xBB8AB8DC, 0x54BAD3C5,
@@ -517,7 +520,7 @@ public void update(int b)
0x37F2D291, 0xD8C2B988, 0xEC7E7252, 0x034E194B,
0x8507E5E6, 0x6A378EFF, 0x5E8B4525, 0xB1BB2E3C
};
- static final int[] T8_6 = new int[]{
+ static final int[] T8_6 = new int[] {
0x00000000, 0x68032CC8, 0xD0065990, 0xB8057558,
0xA5E0C5D1, 0xCDE3E919, 0x75E69C41, 0x1DE5B089,
0x4E2DFD53, 0x262ED19B, 0x9E2BA4C3, 0xF628880B,
@@ -583,7 +586,7 @@ public void update(int b)
0x60F48DC6, 0x08F7A10E, 0xB0F2D456, 0xD8F1F89E,
0xC5144817, 0xAD1764DF, 0x15121187, 0x7D113D4F
};
- static final int[] T8_7 = new int[]{
+ static final int[] T8_7 = new int[] {
0x00000000, 0x493C7D27, 0x9278FA4E, 0xDB448769,
0x211D826D, 0x6821FF4A, 0xB3657823, 0xFA590504,
0x423B04DA, 0x0B0779FD, 0xD043FE94, 0x997F83B3,
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/Slice.java b/leveldb/src/main/java/org/iq80/leveldb/util/Slice.java
index 941ef51d..5094e936 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/Slice.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/Slice.java
@@ -31,12 +31,16 @@
import java.util.Arrays;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
-import static org.iq80.leveldb.util.SizeOf.*;
+import static org.iq80.leveldb.util.SizeOf.SIZE_OF_BYTE;
+import static org.iq80.leveldb.util.SizeOf.SIZE_OF_INT;
+import static org.iq80.leveldb.util.SizeOf.SIZE_OF_LONG;
+import static org.iq80.leveldb.util.SizeOf.SIZE_OF_SHORT;
/**
* Little Endian slice of a byte array.
*/
-public final class Slice implements Comparable
+public final class Slice
+ implements Comparable
{
private final byte[] data;
private final int offset;
@@ -106,7 +110,7 @@ public byte getByte(int index)
/**
* Gets an unsigned byte at the specified absolute {@code index} in this
- * buffer.
+ * buffer.
*
* @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
* {@code index + 1} is greater than {@code this.capacity}
@@ -132,7 +136,7 @@ public short getShort(int index)
/**
* Gets a 32-bit integer at the specified absolute {@code index} in
- * this buffer.
+ * this buffer.
*
* @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
* {@code index + 4} is greater than {@code this.capacity}
@@ -149,7 +153,7 @@ public int getInt(int index)
/**
* Gets a 64-bit long integer at the specified absolute {@code index} in
- * this buffer.
+ * this buffer.
*
* @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
* {@code index + 8} is greater than {@code this.capacity}
@@ -217,7 +221,8 @@ public byte[] getBytes(int index, int length)
index += offset;
if (index == 0) {
return Arrays.copyOf(data, length);
- } else {
+ }
+ else {
byte[] value = new byte[length];
System.arraycopy(data, index, value, 0, length);
return value;
@@ -403,7 +408,7 @@ public void setBytes(int index, ByteBuffer source)
*
* @param length the number of bytes to transfer
* @return the actual number of bytes read in from the specified channel.
- * {@code -1} if the specified channel is closed.
+ * {@code -1} if the specified channel is closed.
* @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
* if {@code index + length} is greater than {@code this.capacity}
* @throws java.io.IOException if the specified stream threw an exception during I/O
@@ -438,7 +443,7 @@ public int setBytes(int index, InputStream in, int length)
*
* @param length the maximum number of bytes to transfer
* @return the actual number of bytes read in from the specified channel.
- * {@code -1} if the specified channel is closed.
+ * {@code -1} if the specified channel is closed.
* @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
* if {@code index + length} is greater than {@code this.capacity}
* @throws java.io.IOException if the specified channel threw an exception during I/O
@@ -539,7 +544,8 @@ public byte[] copyBytes(int index, int length)
index += offset;
if (index == 0) {
return Arrays.copyOf(data, length);
- } else {
+ }
+ else {
byte[] value = new byte[length];
System.arraycopy(data, index, value, 0, length);
return value;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/SliceComparator.java b/leveldb/src/main/java/org/iq80/leveldb/util/SliceComparator.java
index b7fda284..fa244a41 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/SliceComparator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/SliceComparator.java
@@ -19,7 +19,8 @@
import java.util.Comparator;
-public final class SliceComparator implements Comparator
+public final class SliceComparator
+ implements Comparator
{
public static final SliceComparator SLICE_COMPARATOR = new SliceComparator();
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/SliceInput.java b/leveldb/src/main/java/org/iq80/leveldb/util/SliceInput.java
index b8107168..731e08eb 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/SliceInput.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/SliceInput.java
@@ -25,7 +25,9 @@
import java.nio.channels.GatheringByteChannel;
import java.nio.charset.Charset;
-public final class SliceInput extends InputStream implements DataInput
+public final class SliceInput
+ extends InputStream
+ implements DataInput
{
private final Slice slice;
private int position;
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/SliceOutput.java b/leveldb/src/main/java/org/iq80/leveldb/util/SliceOutput.java
index b0b3935f..b35f402d 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/SliceOutput.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/SliceOutput.java
@@ -26,7 +26,9 @@
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
-public abstract class SliceOutput extends OutputStream implements DataOutput
+public abstract class SliceOutput
+ extends OutputStream
+ implements DataOutput
{
/**
* Resets this stream to the initial position.
@@ -68,8 +70,7 @@ public final void write(int value)
* and increases the {@code writerIndex} by {@code 1} in this buffer.
* The 24 high-order bits of the specified value are ignored.
*
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 1}
+ * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 1}
*/
public abstract void writeByte(int value);
@@ -78,8 +79,7 @@ public final void write(int value)
* {@code writerIndex} and increases the {@code writerIndex} by {@code 2}
* in this buffer. The 16 high-order bits of the specified value are ignored.
*
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 2}
+ * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 2}
*/
public abstract void writeShort(int value);
@@ -87,8 +87,7 @@ public final void write(int value)
* Sets the specified 32-bit integer at the current {@code writerIndex}
* and increases the {@code writerIndex} by {@code 4} in this buffer.
*
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 4}
+ * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 4}
*/
public abstract void writeInt(int value);
@@ -97,8 +96,7 @@ public final void write(int value)
* {@code writerIndex} and increases the {@code writerIndex} by {@code 8}
* in this buffer.
*
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 8}
+ * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 8}
*/
public abstract void writeLong(long value);
@@ -112,10 +110,8 @@ public final void write(int value)
* the transferred bytes while {@link #writeBytes(Slice, int, int)}
* does not.
*
- * @throws IndexOutOfBoundsException
- * if {@code source.readableBytes} is greater than
- * {@code this.writableBytes}
- *
+ * @throws IndexOutOfBoundsException if {@code source.readableBytes} is greater than
+ * {@code this.writableBytes}
*/
public abstract void writeBytes(Slice source);
@@ -129,10 +125,8 @@ public final void write(int value)
* {@link #writeBytes(Slice, int, int)} does not.
*
* @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.writableBytes} or
- * if {@code length} is greater then {@code source.readableBytes}
+ * @throws IndexOutOfBoundsException if {@code length} is greater than {@code this.writableBytes} or
+ * if {@code length} is greater then {@code source.readableBytes}
*/
public abstract void writeBytes(SliceInput source, int length);
@@ -142,13 +136,11 @@ public final void write(int value)
* by the number of the transferred bytes (= {@code length}).
*
* @param sourceIndex the first index of the source
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code sourceIndex} is less than {@code 0},
- * if {@code sourceIndex + length} is greater than
- * {@code source.capacity}, or
- * if {@code length} is greater than {@code this.writableBytes}
+ * @param length the number of bytes to transfer
+ * @throws IndexOutOfBoundsException if the specified {@code sourceIndex} is less than {@code 0},
+ * if {@code sourceIndex + length} is greater than
+ * {@code source.capacity}, or
+ * if {@code length} is greater than {@code this.writableBytes}
*/
public abstract void writeBytes(Slice source, int sourceIndex, int length);
@@ -164,8 +156,7 @@ public final void write(byte[] source)
* the current {@code writerIndex} and increases the {@code writerIndex}
* by the number of the transferred bytes (= {@code source.length}).
*
- * @throws IndexOutOfBoundsException
- * if {@code source.length} is greater than {@code this.writableBytes}
+ * @throws IndexOutOfBoundsException if {@code source.length} is greater than {@code this.writableBytes}
*/
public abstract void writeBytes(byte[] source);
@@ -181,13 +172,11 @@ public final void write(byte[] source, int sourceIndex, int length)
* by the number of the transferred bytes (= {@code length}).
*
* @param sourceIndex the first index of the source
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code sourceIndex} is less than {@code 0},
- * if {@code sourceIndex + length} is greater than
- * {@code source.length}, or
- * if {@code length} is greater than {@code this.writableBytes}
+ * @param length the number of bytes to transfer
+ * @throws IndexOutOfBoundsException if the specified {@code sourceIndex} is less than {@code 0},
+ * if {@code sourceIndex + length} is greater than
+ * {@code source.length}, or
+ * if {@code length} is greater than {@code this.writableBytes}
*/
public abstract void writeBytes(byte[] source, int sourceIndex, int length);
@@ -197,9 +186,8 @@ public final void write(byte[] source, int sourceIndex, int length)
* reaches its limit, and increases the {@code writerIndex} by the
* number of the transferred bytes.
*
- * @throws IndexOutOfBoundsException
- * if {@code source.remaining()} is greater than
- * {@code this.writableBytes}
+ * @throws IndexOutOfBoundsException if {@code source.remaining()} is greater than
+ * {@code this.writableBytes}
*/
public abstract void writeBytes(ByteBuffer source);
@@ -209,15 +197,12 @@ public final void write(byte[] source, int sourceIndex, int length)
* {@code writerIndex} by the number of the transferred bytes.
*
* @param length the number of bytes to transfer
- *
* @return the actual number of bytes read in from the specified stream
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.writableBytes}
- * @throws java.io.IOException
- * if the specified stream threw an exception during I/O
+ * @throws IndexOutOfBoundsException if {@code length} is greater than {@code this.writableBytes}
+ * @throws java.io.IOException if the specified stream threw an exception during I/O
*/
- public abstract int writeBytes(InputStream in, int length) throws IOException;
+ public abstract int writeBytes(InputStream in, int length)
+ throws IOException;
/**
* Transfers the content of the specified channel to this buffer
@@ -225,17 +210,15 @@ public final void write(byte[] source, int sourceIndex, int length)
* {@code writerIndex} by the number of the transferred bytes.
*
* @param length the maximum number of bytes to transfer
- *
* @return the actual number of bytes read in from the specified channel
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.writableBytes}
- * @throws java.io.IOException
- * if the specified channel threw an exception during I/O
+ * @throws IndexOutOfBoundsException if {@code length} is greater than {@code this.writableBytes}
+ * @throws java.io.IOException if the specified channel threw an exception during I/O
*/
- public abstract int writeBytes(ScatteringByteChannel in, int length) throws IOException;
+ public abstract int writeBytes(ScatteringByteChannel in, int length)
+ throws IOException;
- public abstract int writeBytes(FileChannel in, int position, int length) throws IOException;
+ public abstract int writeBytes(FileChannel in, int position, int length)
+ throws IOException;
/**
* Fills this buffer with NUL (0x00) starting at the current
@@ -243,9 +226,7 @@ public final void write(byte[] source, int sourceIndex, int length)
* specified {@code length}.
*
* @param length the number of NULs to write to the buffer
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.writableBytes}
+ * @throws IndexOutOfBoundsException if {@code length} is greater than {@code this.writableBytes}
*/
public abstract void writeZero(int length);
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/Slices.java b/leveldb/src/main/java/org/iq80/leveldb/util/Slices.java
index 78d5f268..d6dd6229 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/Slices.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/Slices.java
@@ -19,7 +19,6 @@
import com.google.common.base.Preconditions;
-import javax.xml.transform.Source;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
@@ -236,7 +235,6 @@ private static CharsetEncoder getEncoder(Charset charset)
return e;
}
-
/**
* Returns a cached thread-local {@link CharsetDecoder} for the specified
* charset.
@@ -262,5 +260,4 @@ private static CharsetDecoder getDecoder(Charset charset)
map.put(charset, d);
return d;
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/Snappy.java b/leveldb/src/main/java/org/iq80/leveldb/util/Snappy.java
index 463731f0..15ba3d2d 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/Snappy.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/Snappy.java
@@ -25,79 +25,116 @@
* A Snappy abstraction which attempts uses the iq80 implementation and falls back
* to the xerial Snappy implementation it cannot be loaded. You can change the
* load order by setting the 'leveldb.snappy' system property. Example:
- *
+ *
*
* -Dleveldb.snappy=xerial,iq80
*
- *
+ *
* The system property can also be configured with the name of a class which
* implements the Snappy.SPI interface.
*
*
* @author Hiram Chirino
*/
-public class Snappy {
-
- public static interface SPI {
- public int uncompress(ByteBuffer compressed, ByteBuffer uncompressed) throws IOException;
- public int uncompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) throws IOException;
- public int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) throws IOException;
- public byte[] compress(String text) throws IOException;
- public int maxCompressedLength(int length);
+public final class Snappy
+{
+ private Snappy()
+ {
+ }
+
+ public interface SPI
+ {
+ int uncompress(ByteBuffer compressed, ByteBuffer uncompressed)
+ throws IOException;
+
+ int uncompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset)
+ throws IOException;
+
+ int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset)
+ throws IOException;
+
+ byte[] compress(String text)
+ throws IOException;
+
+ int maxCompressedLength(int length);
}
- public static class XerialSnappy implements SPI {
+ public static class XerialSnappy
+ implements SPI
+ {
static {
// Make sure that the JNI libs are fully loaded.
try {
org.xerial.snappy.Snappy.compress("test");
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw new RuntimeException(e);
}
}
-
- public int uncompress(ByteBuffer compressed, ByteBuffer uncompressed) throws IOException {
+
+ @Override
+ public int uncompress(ByteBuffer compressed, ByteBuffer uncompressed)
+ throws IOException
+ {
return org.xerial.snappy.Snappy.uncompress(compressed, uncompressed);
}
- public int uncompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) throws IOException {
+ @Override
+ public int uncompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset)
+ throws IOException
+ {
return org.xerial.snappy.Snappy.uncompress(input, inputOffset, length, output, outputOffset);
}
- public int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) throws IOException {
+ @Override
+ public int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset)
+ throws IOException
+ {
return org.xerial.snappy.Snappy.compress(input, inputOffset, length, output, outputOffset);
}
- public byte[] compress(String text) throws IOException {
+ @Override
+ public byte[] compress(String text)
+ throws IOException
+ {
return org.xerial.snappy.Snappy.compress(text);
}
- public int maxCompressedLength(int length) {
+ @Override
+ public int maxCompressedLength(int length)
+ {
return org.xerial.snappy.Snappy.maxCompressedLength(length);
}
}
-
- public static class IQ80Snappy implements SPI {
+
+ public static class IQ80Snappy
+ implements SPI
+ {
static {
// Make sure that the library can fully load.
try {
new IQ80Snappy().compress("test");
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw new RuntimeException(e);
}
}
- public int uncompress(ByteBuffer compressed, ByteBuffer uncompressed) throws IOException {
+ @Override
+ public int uncompress(ByteBuffer compressed, ByteBuffer uncompressed)
+ throws IOException
+ {
byte[] input;
int inputOffset;
int length;
byte[] output;
int outputOffset;
- if( compressed.hasArray() ) {
+ if (compressed.hasArray()) {
input = compressed.array();
inputOffset = compressed.arrayOffset() + compressed.position();
length = compressed.remaining();
- } else {
+ }
+ else {
input = new byte[compressed.remaining()];
inputOffset = 0;
length = input.length;
@@ -105,19 +142,21 @@ public int uncompress(ByteBuffer compressed, ByteBuffer uncompressed) throws IOE
compressed.get(input);
compressed.reset();
}
- if( uncompressed.hasArray() ) {
+ if (uncompressed.hasArray()) {
output = uncompressed.array();
outputOffset = uncompressed.arrayOffset() + uncompressed.position();
- } else {
+ }
+ else {
int t = org.iq80.snappy.Snappy.getUncompressedLength(input, inputOffset);
output = new byte[t];
outputOffset = 0;
}
int count = org.iq80.snappy.Snappy.uncompress(input, inputOffset, length, output, outputOffset);
- if( uncompressed.hasArray() ) {
- uncompressed.limit(uncompressed.position()+count);
- } else {
+ if (uncompressed.hasArray()) {
+ uncompressed.limit(uncompressed.position() + count);
+ }
+ else {
int p = uncompressed.position();
uncompressed.limit(uncompressed.capacity());
uncompressed.put(output, 0, count);
@@ -126,15 +165,24 @@ public int uncompress(ByteBuffer compressed, ByteBuffer uncompressed) throws IOE
return count;
}
- public int uncompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) throws IOException {
- return org.iq80.snappy.Snappy.uncompress(input, inputOffset, length, output, outputOffset);
+ @Override
+ public int uncompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset)
+ throws IOException
+ {
+ return org.iq80.snappy.Snappy.uncompress(input, inputOffset, length, output, outputOffset);
}
- public int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) throws IOException {
+ @Override
+ public int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset)
+ throws IOException
+ {
return org.iq80.snappy.Snappy.compress(input, inputOffset, length, output, outputOffset);
}
- public byte[] compress(String text) throws IOException {
+ @Override
+ public byte[] compress(String text)
+ throws IOException
+ {
byte[] uncomressed = text.getBytes("UTF-8");
byte[] compressedOut = new byte[maxCompressedLength(uncomressed.length)];
int compressedSize = compress(uncomressed, 0, uncomressed.length, compressedOut, 0);
@@ -143,54 +191,67 @@ public byte[] compress(String text) throws IOException {
return trimmedBuffer;
}
- public int maxCompressedLength(int length) {
+ @Override
+ public int maxCompressedLength(int length)
+ {
return org.iq80.snappy.Snappy.maxCompressedLength(length);
}
}
- static final private SPI SNAPPY;
+ private static final SPI SNAPPY;
+
static {
SPI attempt = null;
String[] factories = System.getProperty("leveldb.snappy", "iq80,xerial").split(",");
- for (int i = 0; i < factories.length && attempt==null; i++) {
+ for (int i = 0; i < factories.length && attempt == null; i++) {
String name = factories[i];
try {
name = name.trim();
- if("xerial".equals(name.toLowerCase())) {
+ if ("xerial".equals(name.toLowerCase())) {
name = "org.iq80.leveldb.util.Snappy$XerialSnappy";
- } else if("iq80".equals(name.toLowerCase())) {
+ }
+ else if ("iq80".equals(name.toLowerCase())) {
name = "org.iq80.leveldb.util.Snappy$IQ80Snappy";
}
attempt = (SPI) Thread.currentThread().getContextClassLoader().loadClass(name).newInstance();
- } catch (Throwable e) {
+ }
+ catch (Throwable e) {
}
}
SNAPPY = attempt;
}
-
- public static boolean available() {
- return SNAPPY !=null;
+ public static boolean available()
+ {
+ return SNAPPY != null;
}
- public static void uncompress(ByteBuffer compressed, ByteBuffer uncompressed) throws IOException {
+ public static void uncompress(ByteBuffer compressed, ByteBuffer uncompressed)
+ throws IOException
+ {
SNAPPY.uncompress(compressed, uncompressed);
}
- public static void uncompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) throws IOException {
+ public static void uncompress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset)
+ throws IOException
+ {
SNAPPY.uncompress(input, inputOffset, length, output, outputOffset);
}
- public static int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset) throws IOException {
+ public static int compress(byte[] input, int inputOffset, int length, byte[] output, int outputOffset)
+ throws IOException
+ {
return SNAPPY.compress(input, inputOffset, length, output, outputOffset);
}
- public static byte[] compress(String text) throws IOException {
+ public static byte[] compress(String text)
+ throws IOException
+ {
return SNAPPY.compress(text);
}
- public static int maxCompressedLength(int length) {
+ public static int maxCompressedLength(int length)
+ {
return SNAPPY.maxCompressedLength(length);
}
-
}
diff --git a/leveldb/src/main/java/org/iq80/leveldb/util/TableIterator.java b/leveldb/src/main/java/org/iq80/leveldb/util/TableIterator.java
index 3552870a..de5a8c17 100644
--- a/leveldb/src/main/java/org/iq80/leveldb/util/TableIterator.java
+++ b/leveldb/src/main/java/org/iq80/leveldb/util/TableIterator.java
@@ -23,7 +23,8 @@
import java.util.Map.Entry;
-public final class TableIterator extends AbstractSeekingIterator
+public final class TableIterator
+ extends AbstractSeekingIterator
{
private final Table table;
private final BlockIterator blockIterator;
diff --git a/leveldb/src/test/java/org/iq80/leveldb/impl/ApiTest.java b/leveldb/src/test/java/org/iq80/leveldb/impl/ApiTest.java
index cd745886..cda24a4f 100755
--- a/leveldb/src/test/java/org/iq80/leveldb/impl/ApiTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/impl/ApiTest.java
@@ -37,39 +37,46 @@
*
* @author Hiram Chirino
*/
-public class ApiTest {
-
+public class ApiTest
+{
File databaseDir = FileUtils.createTempDir("leveldb");
- public static byte[] bytes(String value) {
- if( value == null) {
+ public static byte[] bytes(String value)
+ {
+ if (value == null) {
return null;
}
try {
return value.getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
- public static String asString(byte value[]) {
- if( value == null) {
+ public static String asString(byte[] value)
+ {
+ if (value == null) {
return null;
}
try {
return new String(value, "UTF-8");
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
- public void assertEquals(byte[] arg1, byte[] arg2) {
- assertTrue(Arrays.equals(arg1, arg2), asString(arg1)+" != "+asString(arg2));
+ public void assertEquals(byte[] arg1, byte[] arg2)
+ {
+ assertTrue(Arrays.equals(arg1, arg2), asString(arg1) + " != " + asString(arg2));
}
DBFactory factory = Iq80DBFactory.factory;
- File getTestDirectory(String name) throws IOException {
+ File getTestDirectory(String name)
+ throws IOException
+ {
File rc = new File(databaseDir, name);
factory.destroy(rc, new Options().createIfMissing(true));
rc.mkdirs();
@@ -77,44 +84,44 @@ File getTestDirectory(String name) throws IOException {
}
@Test
- public void testCompaction() throws IOException, DBException {
-
+ public void testCompaction()
+ throws IOException, DBException
+ {
Options options = new Options().createIfMissing(true).compressionType(CompressionType.NONE);
File path = getTestDirectory("testCompaction");
DB db = factory.open(path, options);
System.out.println("Adding");
- for( int i=0 ; i < 1000*1000; i++) {
- if(i%100000 == 0 ) {
- System.out.println(" at: "+i);
+ for (int i = 0; i < 1000 * 1000; i++) {
+ if (i % 100000 == 0) {
+ System.out.println(" at: " + i);
}
- db.put(bytes("key"+i), bytes("value"+i));
+ db.put(bytes("key" + i), bytes("value" + i));
}
db.close();
db = factory.open(path, options);
System.out.println("Deleting");
- for( int i=0 ; i < 1000*1000; i++) {
- if(i%100000 == 0 ) {
- System.out.println(" at: "+i);
+ for (int i = 0; i < 1000 * 1000; i++) {
+ if (i % 100000 == 0) {
+ System.out.println(" at: " + i);
}
- db.delete(bytes("key"+i));
+ db.delete(bytes("key" + i));
}
db.close();
db = factory.open(path, options);
System.out.println("Adding");
- for( int i=0 ; i < 1000*1000; i++) {
- if(i%100000 == 0 ) {
- System.out.println(" at: "+i);
+ for (int i = 0; i < 1000 * 1000; i++) {
+ if (i % 100000 == 0) {
+ System.out.println(" at: " + i);
}
- db.put(bytes("key"+i), bytes("value"+i));
+ db.put(bytes("key" + i), bytes("value" + i));
}
db.close();
}
-
}
diff --git a/leveldb/src/test/java/org/iq80/leveldb/impl/DbImplTest.java b/leveldb/src/test/java/org/iq80/leveldb/impl/DbImplTest.java
index 27e5bdf3..b62047cf 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/impl/DbImplTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/impl/DbImplTest.java
@@ -82,12 +82,11 @@ public void testBackgroundCompaction()
options.createIfMissing(true);
DbImpl db = new DbImpl(options, this.databaseDir);
Random random = new Random(301);
- for(int i=0; i < 200000*STRESS_FACTOR; i++)
- {
- db.put(randomString(random, 64).getBytes(), new byte[]{0x01}, new WriteOptions().sync(false));
+ for (int i = 0; i < 200000 * STRESS_FACTOR; i++) {
+ db.put(randomString(random, 64).getBytes(), new byte[] {0x01}, new WriteOptions().sync(false));
db.get(randomString(random, 64).getBytes());
- if ((i%50000)==0 && i!=0 ) {
- System.out.println(i+" rows written");
+ if ((i % 50000) == 0 && i != 0) {
+ System.out.println(i + " rows written");
}
}
}
@@ -437,7 +436,7 @@ public void testCompactionsGenerateMultipleFiles()
Random random = new Random(301);
List values = newArrayList();
for (int i = 0; i < 80; i++) {
- String value = randomString(random, 100*1024);
+ String value = randomString(random, 100 * 1024);
db.put(key(i), value);
values.add(value);
}
@@ -809,16 +808,16 @@ public void testMultiPassMultipleEntries()
}
}
- @Test (expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Database directory '" + DOES_NOT_EXIST_FILENAME_PATTERN + "'.*")
+ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Database directory '" + DOES_NOT_EXIST_FILENAME_PATTERN + "'.*")
public void testCantCreateDirectoryReturnMessage()
- throws Exception
+ throws Exception
{
new DbStringWrapper(new Options(), new File(DOES_NOT_EXIST_FILENAME));
}
- @Test (expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Database directory.*is not a directory")
+ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Database directory.*is not a directory")
public void testDBDirectoryIsFileRetrunMessage()
- throws Exception
+ throws Exception
{
File databaseFile = new File(databaseDir + "/imafile");
assertTrue(databaseFile.createNewFile());
@@ -875,7 +874,6 @@ private void testDb(DbStringWrapper db, Entry... entries)
private void testDb(DbStringWrapper db, List> entries)
throws IOException
{
-
for (Entry entry : entries) {
db.put(entry.getKey(), entry.getValue());
}
@@ -903,7 +901,7 @@ private void testDb(DbStringWrapper db, List> entries)
assertSequence(seekingIterator, nextEntries.subList(1, nextEntries.size()));
}
- Slice endKey = Slices.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF});
+ Slice endKey = Slices.wrappedBuffer(new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF});
seekingIterator.seek(endKey.toString(Charsets.UTF_8));
assertSequence(seekingIterator, Collections.>emptyList());
}
@@ -955,7 +953,6 @@ static byte[] toByteArray(String value)
return value.getBytes(UTF_8);
}
-
private static String randomString(Random random, int length)
{
char[] chars = new char[length];
@@ -1202,7 +1199,8 @@ private List allEntriesFor(String userKey)
}
- private static class StringDbIterator implements SeekingIterator
+ private static class StringDbIterator
+ implements SeekingIterator
{
private DBIterator iterator;
diff --git a/leveldb/src/test/java/org/iq80/leveldb/impl/LogTest.java b/leveldb/src/test/java/org/iq80/leveldb/impl/LogTest.java
index 18f5050f..cc93c0f4 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/impl/LogTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/impl/LogTest.java
@@ -41,7 +41,7 @@
public class LogTest
{
- private final LogMonitor NO_CORRUPTION_MONITOR = new LogMonitor()
+ private static final LogMonitor NO_CORRUPTION_MONITOR = new LogMonitor()
{
@Override
public void corruption(long bytes, String reason)
@@ -72,7 +72,6 @@ public void testSmallRecord()
testLog(toSlice("dain sundstrom"));
}
-
@Test
public void testMultipleSmallRecords()
throws Exception
diff --git a/leveldb/src/test/java/org/iq80/leveldb/impl/NativeInteropTest.java b/leveldb/src/test/java/org/iq80/leveldb/impl/NativeInteropTest.java
index 1e848fc9..5a1386c7 100755
--- a/leveldb/src/test/java/org/iq80/leveldb/impl/NativeInteropTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/impl/NativeInteropTest.java
@@ -38,52 +38,63 @@
/**
* @author Hiram Chirino
*/
-public class NativeInteropTest {
+public class NativeInteropTest
+{
+ private static final AtomicInteger NEXT_ID = new AtomicInteger();
- private static AtomicInteger NEXT_ID = new AtomicInteger();
+ private final File databaseDir = FileUtils.createTempDir("leveldb");
- File databaseDir = FileUtils.createTempDir("leveldb");
-
- public static byte[] bytes(String value) {
- if( value == null) {
+ public static byte[] bytes(String value)
+ {
+ if (value == null) {
return null;
}
try {
return value.getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
- public static String asString(byte value[]) {
- if( value == null) {
+ public static String asString(byte[] value)
+ {
+ if (value == null) {
return null;
}
try {
return new String(value, "UTF-8");
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
- public void assertEquals(byte[] arg1, byte[] arg2) {
- assertTrue(Arrays.equals(arg1, arg2), asString(arg1)+" != "+asString(arg2));
+ public void assertEquals(byte[] arg1, byte[] arg2)
+ {
+ assertTrue(Arrays.equals(arg1, arg2), asString(arg1) + " != " + asString(arg2));
}
- DBFactory iq80factory = Iq80DBFactory.factory;
- DBFactory jnifactory = Iq80DBFactory.factory;
+ private final DBFactory iq80factory = Iq80DBFactory.factory;
+ private final DBFactory jnifactory;
- public NativeInteropTest() {
+ public NativeInteropTest()
+ {
+ DBFactory jnifactory = Iq80DBFactory.factory;
try {
ClassLoader cl = NativeInteropTest.class.getClassLoader();
jnifactory = (DBFactory) cl.loadClass("org.fusesource.leveldbjni.JniDBFactory").newInstance();
- } catch (Throwable e) {
+ }
+ catch (Throwable e) {
// We cannot create a JniDBFactory on windows :( so just use a Iq80DBFactory for both
// to avoid test failures.
}
+ this.jnifactory = jnifactory;
}
- File getTestDirectory(String name) throws IOException {
+ File getTestDirectory(String name)
+ throws IOException
+ {
File rc = new File(databaseDir, name);
iq80factory.destroy(rc, new Options().createIfMissing(true));
rc.mkdirs();
@@ -91,27 +102,36 @@ File getTestDirectory(String name) throws IOException {
}
@Test
- public void testCRUDviaIQ80() throws IOException, DBException {
+ public void testCRUDviaIQ80()
+ throws IOException, DBException
+ {
crud(iq80factory, iq80factory);
}
@Test
- public void testCRUDviaJNI() throws IOException, DBException {
+ public void testCRUDviaJNI()
+ throws IOException, DBException
+ {
crud(jnifactory, jnifactory);
}
@Test
- public void testCRUDviaIQ80thenJNI() throws IOException, DBException {
+ public void testCRUDviaIQ80thenJNI()
+ throws IOException, DBException
+ {
crud(iq80factory, jnifactory);
}
@Test
- public void testCRUDviaJNIthenIQ80() throws IOException, DBException {
+ public void testCRUDviaJNIthenIQ80()
+ throws IOException, DBException
+ {
crud(jnifactory, iq80factory);
}
- public void crud(DBFactory firstFactory, DBFactory secondFactory) throws IOException, DBException {
-
+ public void crud(DBFactory firstFactory, DBFactory secondFactory)
+ throws IOException, DBException
+ {
Options options = new Options().createIfMissing(true);
File path = getTestDirectory(getClass().getName() + "_" + NEXT_ID.incrementAndGet());
@@ -145,5 +165,4 @@ public void crud(DBFactory firstFactory, DBFactory secondFactory) throws IOExcep
db.close();
}
-
}
diff --git a/leveldb/src/test/java/org/iq80/leveldb/impl/TestFileChannelLogWriter.java b/leveldb/src/test/java/org/iq80/leveldb/impl/TestFileChannelLogWriter.java
index 370f6a57..4499ced8 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/impl/TestFileChannelLogWriter.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/impl/TestFileChannelLogWriter.java
@@ -27,7 +27,6 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
-
public class TestFileChannelLogWriter
{
@Test
@@ -61,9 +60,9 @@ public void testLogRecordBounds()
}
}
- private static class AssertNoCorruptionLogMonitor implements LogMonitor
+ private static class AssertNoCorruptionLogMonitor
+ implements LogMonitor
{
-
@Override
public void corruption(long bytes, String reason)
{
diff --git a/leveldb/src/test/java/org/iq80/leveldb/impl/TestMMapLogWriter.java b/leveldb/src/test/java/org/iq80/leveldb/impl/TestMMapLogWriter.java
index ffa63142..42b0988c 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/impl/TestMMapLogWriter.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/impl/TestMMapLogWriter.java
@@ -27,7 +27,6 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
-
public class TestMMapLogWriter
{
@Test
@@ -61,9 +60,9 @@ public void testLogRecordBounds()
}
}
- private static class AssertNoCorruptionLogMonitor implements LogMonitor
+ private static class AssertNoCorruptionLogMonitor
+ implements LogMonitor
{
-
@Override
public void corruption(long bytes, String reason)
{
@@ -75,6 +74,5 @@ public void corruption(long bytes, Throwable reason)
{
fail("corruption at " + bytes + " reason: " + reason.toString());
}
-
}
}
diff --git a/leveldb/src/test/java/org/iq80/leveldb/table/BlockHelper.java b/leveldb/src/test/java/org/iq80/leveldb/table/BlockHelper.java
index 2d521a6c..e4119569 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/table/BlockHelper.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/table/BlockHelper.java
@@ -36,8 +36,12 @@
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-public class BlockHelper
+public final class BlockHelper
{
+ private BlockHelper()
+ {
+ }
+
public static int estimateBlockSize(int blockRestartInterval, List entries)
{
if (entries.isEmpty()) {
diff --git a/leveldb/src/test/java/org/iq80/leveldb/table/BlockTest.java b/leveldb/src/test/java/org/iq80/leveldb/table/BlockTest.java
index 26f07508..d52516d4 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/table/BlockTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/table/BlockTest.java
@@ -56,7 +56,6 @@ public void testSingleEntry()
public void testMultipleEntriesWithNonSharedKey()
throws Exception
{
-
blockTest(Integer.MAX_VALUE,
BlockHelper.createBlockEntry("beer", "Lagunitas IPA"),
BlockHelper.createBlockEntry("scotch", "Highland Park"));
@@ -142,8 +141,7 @@ private void blockTest(int blockRestartInterval, List entries)
BlockHelper.assertSequence(blockIterator, nextEntries.subList(1, nextEntries.size()));
}
- blockIterator.seek(Slices.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}));
+ blockIterator.seek(Slices.wrappedBuffer(new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}));
BlockHelper.assertSequence(blockIterator, Collections.emptyList());
-
}
}
diff --git a/leveldb/src/test/java/org/iq80/leveldb/table/FileChannelTableTest.java b/leveldb/src/test/java/org/iq80/leveldb/table/FileChannelTableTest.java
index bfb4698e..a801ff8a 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/table/FileChannelTableTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/table/FileChannelTableTest.java
@@ -23,9 +23,12 @@
import java.nio.channels.FileChannel;
import java.util.Comparator;
-public class FileChannelTableTest extends TableTest
+public class FileChannelTableTest
+ extends TableTest
{
- protected Table createTable(String name, FileChannel fileChannel, Comparator comparator, boolean verifyChecksums) throws IOException {
+ protected Table createTable(String name, FileChannel fileChannel, Comparator comparator, boolean verifyChecksums)
+ throws IOException
+ {
return new FileChannelTable(name, fileChannel, comparator, verifyChecksums);
}
}
diff --git a/leveldb/src/test/java/org/iq80/leveldb/table/MMapTableTest.java b/leveldb/src/test/java/org/iq80/leveldb/table/MMapTableTest.java
index 2edcff64..a2145615 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/table/MMapTableTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/table/MMapTableTest.java
@@ -23,9 +23,12 @@
import java.nio.channels.FileChannel;
import java.util.Comparator;
-public class MMapTableTest extends TableTest
+public class MMapTableTest
+ extends TableTest
{
- protected Table createTable(String name, FileChannel fileChannel, Comparator comparator, boolean verifyChecksums) throws IOException {
+ protected Table createTable(String name, FileChannel fileChannel, Comparator comparator, boolean verifyChecksums)
+ throws IOException
+ {
return new MMapTable(name, fileChannel, comparator, verifyChecksums);
}
}
diff --git a/leveldb/src/test/java/org/iq80/leveldb/table/TableTest.java b/leveldb/src/test/java/org/iq80/leveldb/table/TableTest.java
index 10782eb0..e6cbb4f8 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/table/TableTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/table/TableTest.java
@@ -39,14 +39,15 @@
import static java.util.Arrays.asList;
import static org.testng.Assert.assertTrue;
-abstract public class TableTest
+public abstract class TableTest
{
private File file;
private RandomAccessFile randomAccessFile;
private FileChannel fileChannel;
- abstract protected Table createTable(String name, FileChannel fileChannel, Comparator comparator, boolean verifyChecksums) throws IOException;
-
+ protected abstract Table createTable(String name, FileChannel fileChannel, Comparator comparator, boolean verifyChecksums)
+ throws IOException;
+
@Test(expectedExceptions = IllegalArgumentException.class)
public void testEmptyFile()
throws Exception
@@ -61,7 +62,6 @@ public void testEmptyBlock()
tableTest(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
-
@Test
public void testSingleEntrySingleBlock()
throws Exception
@@ -149,7 +149,7 @@ private void tableTest(int blockSize, int blockRestartInterval, List
lastApproximateOffset = approximateOffset;
}
- Slice endKey = Slices.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF});
+ Slice endKey = Slices.wrappedBuffer(new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF});
seekingIterator.seek(endKey);
BlockHelper.assertSequence(seekingIterator, Collections.emptyList());
diff --git a/leveldb/src/test/java/org/iq80/leveldb/util/PureJavaCrc32CTest.java b/leveldb/src/test/java/org/iq80/leveldb/util/PureJavaCrc32CTest.java
index c0f79c37..8669c5b2 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/util/PureJavaCrc32CTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/util/PureJavaCrc32CTest.java
@@ -41,27 +41,27 @@ public void testCrc(int expectedCrc, byte[] data)
public Object[][] data()
{
return new Object[][] {
- new Object[] { 0x8a9136aa, arrayOf(32, (byte) 0) },
- new Object[] { 0x62a8ab43, arrayOf(32, (byte) 0xff) },
- new Object[] { 0x46dd794e, arrayOf(32, new Function()
+ new Object[] {0x8a9136aa, arrayOf(32, (byte) 0)},
+ new Object[] {0x62a8ab43, arrayOf(32, (byte) 0xff)},
+ new Object[] {0x46dd794e, arrayOf(32, new Function()
{
public Byte apply(Integer position)
{
return (byte) position.intValue();
}
- }) },
- new Object[] { 0x113fdb5c, arrayOf(32, new Function()
+ })},
+ new Object[] {0x113fdb5c, arrayOf(32, new Function()
{
public Byte apply(Integer position)
{
return (byte) (31 - position);
}
- }) },
- new Object[] { 0xd9963a56, arrayOf(new int[] {
+ })},
+ new Object[] {0xd9963a56, arrayOf(new int[] {
0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }) }
+ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})}
};
}
@@ -130,5 +130,4 @@ private byte[] arrayOf(int[] bytes)
return result;
}
-
}
diff --git a/leveldb/src/test/java/org/iq80/leveldb/util/SliceComparatorTest.java b/leveldb/src/test/java/org/iq80/leveldb/util/SliceComparatorTest.java
index c0b9f78a..37854f09 100644
--- a/leveldb/src/test/java/org/iq80/leveldb/util/SliceComparatorTest.java
+++ b/leveldb/src/test/java/org/iq80/leveldb/util/SliceComparatorTest.java
@@ -35,13 +35,13 @@ public void testSliceComparison()
> 0);
assertTrue(SLICE_COMPARATOR.compare(
- Slices.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}),
- Slices.wrappedBuffer(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}))
+ Slices.wrappedBuffer(new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}),
+ Slices.wrappedBuffer(new byte[] {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}))
> 0);
assertTrue(SLICE_COMPARATOR.compare(
- Slices.wrappedBuffer(new byte[]{(byte) 0xFF}),
- Slices.wrappedBuffer(new byte[]{(byte) 0x00}))
+ Slices.wrappedBuffer(new byte[] {(byte) 0xFF}),
+ Slices.wrappedBuffer(new byte[] {(byte) 0x00}))
> 0);
assertAllEqual(Slices.copiedBuffer("abcdefghijklmnopqrstuvwxyz", Charsets.UTF_8),
@@ -63,5 +63,4 @@ public static void assertAllEqual(Slice left, Slice right)
assertTrue(SLICE_COMPARATOR.compare(slice, left.slice(0, i)) > 0);
}
}
-
}
diff --git a/pom.xml b/pom.xml
index 6dd78374..de4f2f65 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,4 +76,30 @@
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.11
+
+
+ validate
+
+ check
+
+
+ ${air.check.skip-checkstyle}
+ ${air.check.fail-checkstyle}
+ true
+ true
+ ${air.main.basedir}/src/checkstyle/checks.xml
+ **/com/facebook/presto/operator/PagesIndexOrdering.java
+
+
+
+
+
+
diff --git a/src/checkstyle/checks.xml b/src/checkstyle/checks.xml
new file mode 100644
index 00000000..1bb6a482
--- /dev/null
+++ b/src/checkstyle/checks.xml
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+