From 86a996c3efddb1c03c1e011ed1298101e63b0ef9 Mon Sep 17 00:00:00 2001 From: Xi Liu Date: Mon, 12 Dec 2016 09:19:49 -0800 Subject: [PATCH 1/2] Enable checkstyle plugin for distributedlog-protocol module --- distributedlog-build-tools/pom.xml | 30 ++ .../resources/distributedlog/checkstyle.xml | 443 ++++++++++++++++++ .../resources/distributedlog/suppressions.xml | 29 ++ distributedlog-protocol/pom.xml | 33 ++ .../java/com/twitter/distributedlog/DLSN.java | 67 +-- .../EnvelopedRecordSetReader.java | 14 +- .../EnvelopedRecordSetWriter.java | 25 +- .../com/twitter/distributedlog/LogRecord.java | 75 +-- .../twitter/distributedlog/LogRecordSet.java | 23 +- .../distributedlog/LogRecordWithDLSN.java | 26 +- .../twitter/distributedlog/RecordStream.java | 6 +- .../DistributedLogAnnotations.java | 3 + .../annotations/package-info.java | 21 + .../exceptions/AlreadyClosedException.java | 6 +- .../AlreadyTruncatedTransactionException.java | 4 +- .../exceptions/BKTransmitException.java | 6 +- .../exceptions/ChecksumFailedException.java | 3 + .../exceptions/DLClientClosedException.java | 3 + .../exceptions/DLException.java | 4 +- .../exceptions/DLIllegalStateException.java | 3 + .../exceptions/EndOfStreamException.java | 3 + .../exceptions/FlushException.java | 4 +- .../exceptions/IdleReaderException.java | 5 + .../exceptions/InternalServerException.java | 3 + .../InvalidEnvelopedEntryException.java | 2 +- .../InvalidStreamNameException.java | 3 + .../exceptions/LockCancelledException.java | 3 + .../exceptions/LockingException.java | 4 +- .../exceptions/LogEmptyException.java | 4 +- .../exceptions/LogExistsException.java | 2 +- .../exceptions/LogNotFoundException.java | 4 +- .../exceptions/LogReadException.java | 1 - .../exceptions/LogRecordTooLongException.java | 5 + .../exceptions/MetadataException.java | 3 + .../NotYetImplementedException.java | 3 + .../exceptions/OverCapacityException.java | 6 + .../OwnershipAcquireFailedException.java | 5 + .../exceptions/ReadCancelledException.java | 3 + .../RegionUnavailableException.java | 5 + .../exceptions/RequestDeniedException.java | 3 + .../exceptions/RetryableReadException.java | 3 + .../ServiceUnavailableException.java | 3 + .../exceptions/StreamNotReadyException.java | 3 + .../StreamUnavailableException.java | 3 + .../exceptions/TooManyStreamsException.java | 3 + .../TransactionIdOutOfOrderException.java | 3 + .../exceptions/UnexpectedException.java | 3 + .../UnsupportedMetadataVersionException.java | 3 + .../exceptions/WriteCancelledException.java | 11 +- .../exceptions/WriteException.java | 6 +- .../exceptions/package-info.java | 21 + .../distributedlog/io/CompressionCodec.java | 5 +- .../distributedlog/io/CompressionUtils.java | 15 +- .../io/IdentityCompressionCodec.java | 15 +- .../io/LZ4CompressionCodec.java | 37 +- .../distributedlog/io/package-info.java | 21 + .../twitter/distributedlog/package-info.java | 21 + .../distributedlog/util/BitMaskUtils.java | 13 +- .../distributedlog/util/ProtocolUtils.java | 5 +- .../distributedlog/util/package-info.java | 21 + .../com/twitter/distributedlog/TestDLSN.java | 7 +- .../distributedlog/TestLogRecordSet.java | 17 +- pom.xml | 1 + 63 files changed, 957 insertions(+), 178 deletions(-) create mode 100644 distributedlog-build-tools/pom.xml create mode 100644 distributedlog-build-tools/src/main/resources/distributedlog/checkstyle.xml create mode 100644 distributedlog-build-tools/src/main/resources/distributedlog/suppressions.xml create mode 100644 distributedlog-protocol/src/main/java/com/twitter/distributedlog/annotations/package-info.java create mode 100644 distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/package-info.java create mode 100644 distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/package-info.java create mode 100644 distributedlog-protocol/src/main/java/com/twitter/distributedlog/package-info.java create mode 100644 distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/package-info.java diff --git a/distributedlog-build-tools/pom.xml b/distributedlog-build-tools/pom.xml new file mode 100644 index 000000000..45b0b8105 --- /dev/null +++ b/distributedlog-build-tools/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + com.twitter + distributedlog + 0.4.0-incubating-SNAPSHOT + ../pom.xml + + distributedlog-build-tools + Apache DistributedLog :: Build Tools + 0.4.0-incubating-SNAPSHOT + diff --git a/distributedlog-build-tools/src/main/resources/distributedlog/checkstyle.xml b/distributedlog-build-tools/src/main/resources/distributedlog/checkstyle.xml new file mode 100644 index 000000000..45be45e16 --- /dev/null +++ b/distributedlog-build-tools/src/main/resources/distributedlog/checkstyle.xml @@ -0,0 +1,443 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/distributedlog-build-tools/src/main/resources/distributedlog/suppressions.xml b/distributedlog-build-tools/src/main/resources/distributedlog/suppressions.xml new file mode 100644 index 000000000..9f60c2549 --- /dev/null +++ b/distributedlog-build-tools/src/main/resources/distributedlog/suppressions.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + diff --git a/distributedlog-protocol/pom.xml b/distributedlog-protocol/pom.xml index 48b749ae3..ae9cb4677 100644 --- a/distributedlog-protocol/pom.xml +++ b/distributedlog-protocol/pom.xml @@ -107,6 +107,39 @@ ${basedir}/src/main/resources/findbugsExclude.xml + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.puppycrawl.tools + checkstyle + 6.19 + + + com.twitter + distributedlog-build-tools + ${project.version} + + + + distributedlog/checkstyle.xml + distributedlog/suppressions.xml + true + true + false + true + + + + test-compile + + check + + + + diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/DLSN.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/DLSN.java index 9e3b76c1a..57cc0ef36 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/DLSN.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/DLSN.java @@ -17,12 +17,13 @@ */ package com.twitter.distributedlog; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; +import java.nio.ByteBuffer; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; -import java.nio.ByteBuffer; /** * DistributedLog Sequence Number (DLSN) is the system generated sequence number for log record. @@ -46,7 +47,7 @@ public class DLSN implements Comparable { // The non-inclusive lower bound DLSN public static final DLSN NonInclusiveLowerBound = new DLSN(1, 0 , -1); // Invalid DLSN - public static final DLSN InvalidDLSN = new DLSN(0,-1,-1); + public static final DLSN InvalidDLSN = new DLSN(0, -1, -1); static final byte CUR_VERSION = VERSION1; static final int VERSION0_LEN = Long.SIZE * 3 + Byte.SIZE; @@ -71,14 +72,6 @@ public long getLogSegmentSequenceNo() { return logSegmentSequenceNo; } - /** - * use {@link #getLogSegmentSequenceNo()} instead - */ - @Deprecated - long getLedgerSequenceNo() { - return logSegmentSequenceNo; - } - /** * Return the entry id of the batch that the record is written to. * @@ -100,11 +93,11 @@ public long getSlotId() { @Override public int compareTo(DLSN that) { if (this.logSegmentSequenceNo != that.logSegmentSequenceNo) { - return (this.logSegmentSequenceNo < that.logSegmentSequenceNo)? -1 : 1; + return (this.logSegmentSequenceNo < that.logSegmentSequenceNo) ? -1 : 1; } else if (this.entryId != that.entryId) { - return (this.entryId < that.entryId)? -1 : 1; + return (this.entryId < that.entryId) ? -1 : 1; } else { - return (this.slotId < that.slotId)? -1 : (this.slotId == that.slotId)? 0 : 1; + return (this.slotId < that.slotId) ? -1 : (this.slotId == that.slotId) ? 0 : 1; } } @@ -125,7 +118,7 @@ public byte[] serializeBytes() { * @return the serialized bytes */ public byte[] serializeBytes(byte version) { - Preconditions.checkArgument(version <= CUR_VERSION && version >= VERSION0); + checkArgument(version <= CUR_VERSION && version >= VERSION0); byte[] data = new byte[CUR_VERSION == version ? VERSION1_LEN : VERSION0_LEN]; ByteBuffer bb = ByteBuffer.wrap(data); bb.put(version); @@ -208,23 +201,33 @@ static DLSN deserialize0(String dlsn) { @Override public String toString() { - return "DLSN{" + - "logSegmentSequenceNo=" + logSegmentSequenceNo + - ", entryId=" + entryId + - ", slotId=" + slotId + - '}'; + return "DLSN{" + + "logSegmentSequenceNo=" + logSegmentSequenceNo + + ", entryId=" + entryId + + ", slotId=" + slotId + + '}'; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DLSN)) return false; + if (this == o) { + return true; + } + if (!(o instanceof DLSN)) { + return false; + } DLSN dlsn = (DLSN) o; - if (entryId != dlsn.entryId) return false; - if (logSegmentSequenceNo != dlsn.logSegmentSequenceNo) return false; - if (slotId != dlsn.slotId) return false; + if (entryId != dlsn.entryId) { + return false; + } + if (logSegmentSequenceNo != dlsn.logSegmentSequenceNo) { + return false; + } + if (slotId != dlsn.slotId) { + return false; + } return true; } @@ -238,9 +241,10 @@ public int hashCode() { } /** - * Positions to a DLSN greater than the current value - this may not - * correspond to an actual LogRecord, its just used by the positioning logic - * to position the reader + * Positions to a DLSN greater than the current value. + * + *

This may not correspond to an actual LogRecord, its just used by the positioning logic + * to position the reader. * * @return the next DLSN */ @@ -249,9 +253,10 @@ public DLSN getNextDLSN() { } /** - * Positions to a DLSN greater than the current value - this may not - * correspond to an actual LogRecord, its just used by the positioning logic - * to position the reader + * Positions to next log segment than the current value. + * + *

this may not correspond to an actual LogRecord, its just used by the positioning logic + * to position the reader. * * @return the next DLSN */ diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/EnvelopedRecordSetReader.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/EnvelopedRecordSetReader.java index d3f7a99e4..dae8403a8 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/EnvelopedRecordSetReader.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/EnvelopedRecordSetReader.java @@ -17,15 +17,19 @@ */ package com.twitter.distributedlog; +import static com.twitter.distributedlog.LogRecordSet.COMPRESSION_CODEC_LZ4; +import static com.twitter.distributedlog.LogRecordSet.METADATA_COMPRESSION_MASK; +import static com.twitter.distributedlog.LogRecordSet.METADATA_VERSION_MASK; +import static com.twitter.distributedlog.LogRecordSet.NULL_OP_STATS_LOGGER; +import static com.twitter.distributedlog.LogRecordSet.VERSION; + import com.twitter.distributedlog.io.CompressionCodec; import com.twitter.distributedlog.io.CompressionUtils; - import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; -import static com.twitter.distributedlog.LogRecordSet.*; /** * Record reader to read records from an enveloped entry buffer. @@ -63,8 +67,8 @@ class EnvelopedRecordSetReader implements LogRecordSet.Reader { int metadata = src.readInt(); int version = metadata & METADATA_VERSION_MASK; if (version != VERSION) { - throw new IOException(String.format("Version mismatch while reading. Received: %d," + - " Required: %d", version, VERSION)); + throw new IOException(String.format("Version mismatch while reading. Received: %d," + + " Required: %d", version, VERSION)); } int codecCode = metadata & METADATA_COMPRESSION_MASK; this.numRecords = src.readInt(); @@ -76,7 +80,7 @@ class EnvelopedRecordSetReader implements LogRecordSet.Reader { if (COMPRESSION_CODEC_LZ4 == codecCode) { CompressionCodec codec = CompressionUtils.getCompressionCodec(CompressionCodec.Type.LZ4); byte[] decompressedData = codec.decompress(compressedData, 0, actualDataLen, - originDataLen, NullOpStatsLogger); + originDataLen, NULL_OP_STATS_LOGGER); this.reader = ByteBuffer.wrap(decompressedData); } else { if (originDataLen != actualDataLen) { diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/EnvelopedRecordSetWriter.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/EnvelopedRecordSetWriter.java index 32b3cf4fa..7f64a6d52 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/EnvelopedRecordSetWriter.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/EnvelopedRecordSetWriter.java @@ -17,15 +17,21 @@ */ package com.twitter.distributedlog; +import static com.twitter.distributedlog.LogRecord.MAX_LOGRECORD_SIZE; +import static com.twitter.distributedlog.LogRecordSet.COMPRESSION_CODEC_LZ4; +import static com.twitter.distributedlog.LogRecordSet.COMPRESSION_CODEC_NONE; +import static com.twitter.distributedlog.LogRecordSet.HEADER_LEN; +import static com.twitter.distributedlog.LogRecordSet.METADATA_COMPRESSION_MASK; +import static com.twitter.distributedlog.LogRecordSet.METADATA_VERSION_MASK; +import static com.twitter.distributedlog.LogRecordSet.NULL_OP_STATS_LOGGER; +import static com.twitter.distributedlog.LogRecordSet.VERSION; + +import com.twitter.distributedlog.exceptions.LogRecordTooLongException; +import com.twitter.distributedlog.exceptions.WriteException; import com.twitter.distributedlog.io.Buffer; import com.twitter.distributedlog.io.CompressionCodec; import com.twitter.distributedlog.io.CompressionUtils; -import com.twitter.distributedlog.exceptions.LogRecordTooLongException; -import com.twitter.distributedlog.exceptions.WriteException; import com.twitter.util.Promise; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; @@ -33,16 +39,15 @@ import java.nio.channels.WritableByteChannel; import java.util.LinkedList; import java.util.List; - -import static com.twitter.distributedlog.LogRecord.MAX_LOGRECORD_SIZE; -import static com.twitter.distributedlog.LogRecordSet.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * {@link Buffer} based log record set writer. */ class EnvelopedRecordSetWriter implements LogRecordSet.Writer { - static final Logger logger = LoggerFactory.getLogger(EnvelopedRecordSetWriter.class); + private static final Logger logger = LoggerFactory.getLogger(EnvelopedRecordSetWriter.class); private final Buffer buffer; private final DataOutputStream writer; @@ -158,7 +163,7 @@ ByteBuffer createBuffer() { CompressionCodec compressor = CompressionUtils.getCompressionCodec(codec); byte[] compressed = - compressor.compress(data, dataOffset, dataLen, NullOpStatsLogger); + compressor.compress(data, dataOffset, dataLen, NULL_OP_STATS_LOGGER); ByteBuffer recordSetBuffer; if (compressed.length > dataLen) { diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecord.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecord.java index c104212f1..74df400c3 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecord.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecord.java @@ -17,14 +17,13 @@ */ package com.twitter.distributedlog; +import com.google.common.annotations.VisibleForTesting; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; - -import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,38 +40,39 @@ * *

User Record

* - * User records are the records written by applications and read by applications. They + *

User records are the records written by applications and read by applications. They * are constructed via {@link #LogRecord(long, byte[])} by applications and appended to * logs by writers. And they would be deserialized from bytes by the readers and return * to applications. * *

Control Record

* - * Control records are special records that written by distributedlog. They are invisible + *

Control records are special records that written by distributedlog. They are invisible * to applications. They could be treated as commit requests as what people could find * in distributed consensus algorithms, since they are usually written by distributedlog to * commit application written records. Commit means making application written records * visible to readers to achieve consistent views among them. - *

- * They are named as 'Control Records' for controlling visibility of application written records. - *

- * The transaction id of 'Control Records' are assigned by distributedlog by inheriting from last + * + *

They are named as 'Control Records' for controlling visibility of application written records. + * + *

The transaction id of 'Control Records' are assigned by distributedlog by inheriting from last * written user records. So we could indicate what user records that a control record is committing * by looking at its transaction id. * *

EndOfStream Record

* - * EoS(EndOfStream) is a special control record that would be written by a writer + *

EoS(EndOfStream) is a special control record that would be written by a writer * to seal a log. After a EoS record is written to a log, no writers could append any record * after that and readers will get {@link com.twitter.distributedlog.exceptions.EndOfStreamException} * when they reach EoS. + * *

TransactionID of EoS is Long.MAX_VALUE. * *

Serialization & Deserialization

* - * Data type in brackets. Interpretation should be on the basis of data types and not individual + *

Data type in brackets. Interpretation should be on the basis of data types and not individual * bytes to honor Endianness. - *

+ * *

  * LogRecord structure:
  * -------------------
@@ -98,13 +98,14 @@
  *
  * 

Sequence Numbers

* - * A record is associated with three types of sequence numbers. They are generated + *

A record is associated with three types of sequence numbers. They are generated * and used for different purposes. Check {@link LogRecordWithDLSN} for more details. * * @see LogRecordWithDLSN */ public class LogRecord { - static final Logger LOG = LoggerFactory.getLogger(LogRecord.class); + + private static final Logger LOG = LoggerFactory.getLogger(LogRecord.class); // Allow 4K overhead for metadata within the max transmission size public static final int MAX_LOGRECORD_SIZE = 1024 * 1024 - 8 * 1024; //1MB - 8KB @@ -131,8 +132,8 @@ public class LogRecord { /** * Construct an uninitialized log record. - *

- * NOTE: only deserializer should call this constructor. + * + *

NOTE: only deserializer should call this constructor. */ protected LogRecord() { this.txid = 0; @@ -141,6 +142,7 @@ protected LogRecord() { /** * Construct a log record with TransactionId and payload. + * *

Usually writer would construct the log record for writing. * * @param txid @@ -223,8 +225,8 @@ protected long getMetadata() { */ void setPositionWithinLogSegment(int positionWithinLogSegment) { assert(positionWithinLogSegment >= 0); - metadata = (metadata & LOGRECORD_METADATA_POSITION_UMASK) | - (((long) positionWithinLogSegment) << LOGRECORD_METADATA_POSITION_SHIFT); + metadata = (metadata & LOGRECORD_METADATA_POSITION_UMASK) + | (((long) positionWithinLogSegment) << LOGRECORD_METADATA_POSITION_SHIFT); } /** @@ -243,6 +245,7 @@ public int getPositionWithinLogSegment() { /** * Get the last position of this record in the log segment. + * *

If the record isn't record set, it would be same as {@link #getPositionWithinLogSegment()}, * otherwise, it would be {@link #getPositionWithinLogSegment()} + numRecords - 1. If the record set * version is unknown, it would be same as {@link #getPositionWithinLogSegment()}. @@ -264,6 +267,7 @@ int getLastPositionWithinLogSegment() { /** * Set the record to represent a set of records. + * *

The bytes in this record is the serialized format of {@link LogRecordSet}. */ public void setRecordSet() { @@ -319,6 +323,7 @@ void setEndOfStream() { /** * Check if the record is a EoS mark. + * *

EoS mark is a special record that writer would * add to seal a log. after Eos mark is written, * writers can't write any more records and readers will get @@ -356,8 +361,9 @@ private void writeToStream(DataOutputStream out) throws IOException { } /** - * The size of the serialized log record, this is used to estimate how much will - * be be appended to the in-memory buffer + * The size of the serialized log record. + * + *

This is used to estimate how much will be be appended to the in-memory buffer. * * @return serialized size */ @@ -367,7 +373,7 @@ int getPersistentSize() { } /** - * Class for writing log records + * Writer class to write log records into an output {@code stream}. */ public static class Writer { private final DataOutputStream buf; @@ -377,7 +383,7 @@ public Writer(DataOutputStream out) { } /** - * Write an operation to the output stream + * Write an operation to the output stream. * * @param record The operation to write * @throws IOException if an error occurs during writing. @@ -392,8 +398,7 @@ public int getPendingBytes() { } /** - * This class is a package private class for reading log records - * from the persistent + * Reader class to read log records from an input {@code stream}. */ public static class Reader { private final RecordStream recordStream; @@ -405,9 +410,11 @@ public static class Reader { private LogRecordWithDLSN lastRecordSkipTo = null; /** - * Construct the reader + * Construct the reader. * + * @param recordStream the record stream for generating {@code DLSN}s. * @param in The stream to read from. + * @param startSequenceId the start sequence id. */ public Reader(RecordStream recordStream, DataInputStream in, @@ -426,9 +433,9 @@ public Reader(RecordStream recordStream, } /** - * Read an operation from the input stream. - *

- * Note that the objects returned from this method may be re-used by future + * Read an log record from the input stream. + * + *

Note that the objects returned from this method may be re-used by future * calls to the same method. * * @return the operation read from the stream, or null at the end of the file @@ -466,9 +473,11 @@ public LogRecordWithDLSN readOp() throws IOException { nextRecordInStream.readPayload(in); if (LOG.isTraceEnabled()) { if (nextRecordInStream.isControl()) { - LOG.trace("Reading {} Control DLSN {}", recordStream.getName(), nextRecordInStream.getDlsn()); + LOG.trace("Reading {} Control DLSN {}", + recordStream.getName(), nextRecordInStream.getDlsn()); } else { - LOG.trace("Reading {} Valid DLSN {}", recordStream.getName(), nextRecordInStream.getDlsn()); + LOG.trace("Reading {} Valid DLSN {}", + recordStream.getName(), nextRecordInStream.getDlsn()); } } @@ -525,7 +534,7 @@ private boolean skipTo(Long txId, DLSN dlsn, boolean skipControl) throws IOExcep currTxId = lastRecordSkipTo.getTransactionId(); } - if ((null != dlsn) && (recordStream.getCurrentPosition().compareTo(dlsn) >=0)) { + if ((null != dlsn) && (recordStream.getCurrentPosition().compareTo(dlsn) >= 0)) { if (LOG.isTraceEnabled()) { LOG.trace("Found position {} beyond {}", recordStream.getCurrentPosition(), dlsn); } @@ -556,7 +565,8 @@ private boolean skipTo(Long txId, DLSN dlsn, boolean skipControl) throws IOExcep // get the num of records to skip if (isRecordSet(flags)) { // read record set - LogRecordWithDLSN record = new LogRecordWithDLSN(recordStream.getCurrentPosition(), startSequenceId); + LogRecordWithDLSN record = + new LogRecordWithDLSN(recordStream.getCurrentPosition(), startSequenceId); record.setMetadata(flags); record.setTransactionId(currTxId); record.readPayload(in); @@ -580,7 +590,8 @@ private boolean skipTo(Long txId, DLSN dlsn, boolean skipControl) throws IOExcep read += bytesToRead; } if (LOG.isTraceEnabled()) { - LOG.trace("Skipped Record with TxId {} DLSN {}", currTxId, recordStream.getCurrentPosition()); + LOG.trace("Skipped Record with TxId {} DLSN {}", + currTxId, recordStream.getCurrentPosition()); } recordStream.advance(1); } diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecordSet.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecordSet.java index dad8e3ece..52970c70b 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecordSet.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecordSet.java @@ -17,20 +17,21 @@ */ package com.twitter.distributedlog; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import com.twitter.distributedlog.exceptions.LogRecordTooLongException; import com.twitter.distributedlog.exceptions.WriteException; import com.twitter.distributedlog.io.CompressionCodec; import com.twitter.util.Promise; -import org.apache.bookkeeper.stats.NullStatsLogger; -import org.apache.bookkeeper.stats.OpStatsLogger; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.ByteBuffer; +import org.apache.bookkeeper.stats.NullStatsLogger; +import org.apache.bookkeeper.stats.OpStatsLogger; /** * A set of {@link LogRecord}s. + * *

  * Structure:
  * Bytes 0  -  4                : Metadata (version + flags)
@@ -56,7 +57,7 @@
  */
 public class LogRecordSet {
 
-    static final OpStatsLogger NullOpStatsLogger =
+    static final OpStatsLogger NULL_OP_STATS_LOGGER =
             NullStatsLogger.INSTANCE.getOpStatsLogger("");
 
     public static final int HEADER_LEN =
@@ -77,7 +78,7 @@ public class LogRecordSet {
     static final int COMPRESSION_CODEC_LZ4 = 0X1;
 
     public static int numRecords(LogRecord record) throws IOException {
-        Preconditions.checkArgument(record.isRecordSet(),
+        checkArgument(record.isRecordSet(),
                 "record is not a recordset");
         byte[] data = record.getPayload();
         return numRecords(data);
@@ -88,8 +89,8 @@ public static int numRecords(byte[] data) throws IOException {
         int metadata = buffer.getInt();
         int version = (metadata & METADATA_VERSION_MASK);
         if (version != VERSION) {
-            throw new IOException(String.format("Version mismatch while reading. Received: %d," +
-                    " Required: %d", version, VERSION));
+            throw new IOException(String.format("Version mismatch while reading. Received: %d,"
+                + " Required: %d", version, VERSION));
         }
         return buffer.getInt();
     }
@@ -100,7 +101,7 @@ public static Writer newWriter(int initialBufferSize,
     }
 
     public static Reader of(LogRecordWithDLSN record) throws IOException {
-        Preconditions.checkArgument(record.isRecordSet(),
+        checkArgument(record.isRecordSet(),
                 "record is not a recordset");
         byte[] data = record.getPayload();
         DLSN dlsn = record.getDlsn();
@@ -120,7 +121,7 @@ public static Reader of(LogRecordWithDLSN record) throws IOException {
     /**
      * Writer to append {@link LogRecord}s to {@link LogRecordSet}.
      */
-    public static interface Writer extends LogRecordSetBuffer {
+    public interface Writer extends LogRecordSetBuffer {
 
         /**
          * Write a {@link LogRecord} to this record set.
@@ -140,7 +141,7 @@ void writeRecord(ByteBuffer record, Promise transmitPromise)
     /**
      * Reader to read {@link LogRecord}s from this record set.
      */
-    public static interface Reader {
+    public interface Reader {
 
         /**
          * Read next log record from this record set.
diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecordWithDLSN.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecordWithDLSN.java
index 521e4520a..14c8e76ea 100644
--- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecordWithDLSN.java
+++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/LogRecordWithDLSN.java
@@ -24,7 +24,7 @@
  *
  * 

Sequence Numbers

* - * A log record will be assigned with an unique system generated sequence number {@link DLSN} when it is + *

A log record will be assigned with an unique system generated sequence number {@link DLSN} when it is * written to a log. At the mean time, a 64-bits long number is assigned to the record indicates its position * within a log, which is called SequenceId. Besides {@link DLSN} and SequenceID, * application can assign its own sequence number (called TransactionID) to the log record while @@ -32,7 +32,7 @@ * *

Transaction ID

* - * Transaction ID is a positive 64-bits long number that is assigned by the application. It is a very helpful + *

Transaction ID is a positive 64-bits long number that is assigned by the application. It is a very helpful * field when application wants to organize the records and position the readers using their own sequencing method. * A typical use case of TransactionID is DistributedLog Write Proxy. It assigns the non-decreasing * timestamps to log records, which the timestamps could be used as `physical time` to implement `TTL` in a strong @@ -40,14 +40,14 @@ * *

DLSN

* - * DistributedLog Sequence Number (DLSN) is the sequence number generated during written time. It is comparable - * and could be used to figure out the order between records. The DLSN is comprised with 3 components. They are - * Log Segment Sequence Number, Entry Id and Slot Id. (See {@link DLSN} for more details). + *

DistributedLog Sequence Number (DLSN) is the sequence number generated during written time. + * It is comparable and could be used to figure out the order between records. The DLSN is comprised with 3 components. + * They are Log Segment Sequence Number, Entry Id and Slot Id. (See {@link DLSN} for more details). * The DLSN is usually used for comparison, positioning and truncation. * *

Sequence ID

* - * Sequence ID is introduced to address the drawback of DLSN, in favor of answering questions like + *

Sequence ID is introduced to address the drawback of DLSN, in favor of answering questions like * `how many records written between two DLSNs`. It is a 64-bits monotonic increasing number (starting from zero). * Sequence ids are only accessible by readers. That means writers don't know the sequence ids of records after they * wrote them. @@ -96,12 +96,12 @@ public DLSN getDlsn() { @Override public String toString() { - return "LogRecordWithDLSN{" + - "dlsn=" + dlsn + - ", txid=" + getTransactionId() + - ", position=" + getPositionWithinLogSegment() + - ", isControl=" + isControl() + - ", isEndOfStream=" + isEndOfStream() + - '}'; + return "LogRecordWithDLSN{" + + "dlsn=" + dlsn + + ", txid=" + getTransactionId() + + ", position=" + getPositionWithinLogSegment() + + ", isControl=" + isControl() + + ", isEndOfStream=" + isEndOfStream() + + '}'; } } diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/RecordStream.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/RecordStream.java index a2b5537ef..d920ea1a1 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/RecordStream.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/RecordStream.java @@ -18,7 +18,7 @@ package com.twitter.distributedlog; /** - * Stream of records + * A iterator to iterate records in the stream. */ public interface RecordStream { /** @@ -27,14 +27,14 @@ public interface RecordStream { void advance(int numRecords); /** - * Get postion of current record in the stream + * Get position of current record in the stream. * * @return position of current record */ DLSN getCurrentPosition(); /** - * Get the name of the stream + * Get the name of the stream. * * @return the name of the stream */ diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/annotations/DistributedLogAnnotations.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/annotations/DistributedLogAnnotations.java index d2d19b235..285900864 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/annotations/DistributedLogAnnotations.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/annotations/DistributedLogAnnotations.java @@ -17,6 +17,9 @@ */ package com.twitter.distributedlog.annotations; +/** + * Common annotation types. + */ public class DistributedLogAnnotations { /** * Annotation to identify flaky tests in DistributedLog. diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/annotations/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/annotations/package-info.java new file mode 100644 index 000000000..24bb36b20 --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/annotations/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +/** + * Defines annotations used across distributedlog project. + */ +package com.twitter.distributedlog.annotations; \ No newline at end of file diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/AlreadyClosedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/AlreadyClosedException.java index f8bb7b834..abbce5f31 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/AlreadyClosedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/AlreadyClosedException.java @@ -17,12 +17,12 @@ */ package com.twitter.distributedlog.exceptions; -import com.twitter.distributedlog.exceptions.DLException; import com.twitter.distributedlog.thrift.service.StatusCode; /** - * Thrown when the distributed log manager has already been closed - * (connections have been torn down) + * Thrown when any distributedlog resources have already been closed. + * + *

For example, it might be thrown when the connections have been torn down. */ public class AlreadyClosedException extends DLException { diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/AlreadyTruncatedTransactionException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/AlreadyTruncatedTransactionException.java index fa3fb4b97..788b4d8b7 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/AlreadyTruncatedTransactionException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/AlreadyTruncatedTransactionException.java @@ -17,12 +17,10 @@ */ package com.twitter.distributedlog.exceptions; -import com.twitter.distributedlog.exceptions.DLException; import com.twitter.distributedlog.thrift.service.StatusCode; /** - * Thrown when the transaction Id specified in the API is in the range that has already been - * truncated + * Thrown when the transaction Id specified in the API is in the range that has already been truncated. */ public class AlreadyTruncatedTransactionException extends DLException { diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/BKTransmitException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/BKTransmitException.java index 158ce3146..8f29628f2 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/BKTransmitException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/BKTransmitException.java @@ -17,12 +17,12 @@ */ package com.twitter.distributedlog.exceptions; -import com.twitter.distributedlog.exceptions.DLException; import com.twitter.distributedlog.thrift.service.StatusCode; /** - * Thrown when the send to bookkeeper fails - * This is thrown by the next attempt to write, send or flush + * Thrown when the send to bookkeeper fails. + * + *

This is thrown by the next attempt to write, send or flush */ public class BKTransmitException extends DLException { diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ChecksumFailedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ChecksumFailedException.java index 111dff6c6..4b6729913 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ChecksumFailedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ChecksumFailedException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception thrown when checksum failures occurred. + */ public class ChecksumFailedException extends DLException { private static final long serialVersionUID = 288438128880378812L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLClientClosedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLClientClosedException.java index 6c947c26a..2f506ba9d 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLClientClosedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLClientClosedException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exceptions thrown when a distributedlog client is closed. + */ public class DLClientClosedException extends DLException { private static final long serialVersionUID = -8876218750540927584L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLException.java index 1e654bfa5..23af0c5d2 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLException.java @@ -19,9 +19,11 @@ import com.twitter.distributedlog.thrift.service.ResponseHeader; import com.twitter.distributedlog.thrift.service.StatusCode; - import java.io.IOException; +/** + * The basic exception of all distributedlog exceptions. + */ public class DLException extends IOException { private static final long serialVersionUID = -4485775468586114393L; protected final StatusCode code; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLIllegalStateException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLIllegalStateException.java index 78e5e9c8f..c80b9db23 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLIllegalStateException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/DLIllegalStateException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a method has been invoked at an illegal or inappropriate time. + */ public class DLIllegalStateException extends DLException { private static final long serialVersionUID = -6721471104777747420L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/EndOfStreamException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/EndOfStreamException.java index 663b18bd1..a62e62996 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/EndOfStreamException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/EndOfStreamException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception thrown when a reader reaches end of a sealed log stream. + */ public class EndOfStreamException extends DLException { private static final long serialVersionUID = -6398949401860680263L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/FlushException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/FlushException.java index 331de00de..f984b6c79 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/FlushException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/FlushException.java @@ -17,9 +17,11 @@ */ package com.twitter.distributedlog.exceptions; -import com.twitter.distributedlog.exceptions.DLException; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception indicates that errors occurred on flushing data. + */ public class FlushException extends DLException { private final long lastTxIdWritten; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/IdleReaderException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/IdleReaderException.java index 475606ffa..1f6923a7e 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/IdleReaderException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/IdleReaderException.java @@ -19,6 +19,11 @@ import java.io.IOException; +/** + * An exception is thrown when a log reader becomes idle. + * + *

A log reader can become idle when there is no records written to the stream. + */ public class IdleReaderException extends IOException { private static final long serialVersionUID = 4882278671396434834L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InternalServerException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InternalServerException.java index 4b463963c..2aea1527d 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InternalServerException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InternalServerException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception indicates that there is an internal error at distributedlog service side. + */ public class InternalServerException extends DLException { private static final long serialVersionUID = 288438028880978802L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InvalidEnvelopedEntryException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InvalidEnvelopedEntryException.java index fdc50c171..09e146c0c 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InvalidEnvelopedEntryException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InvalidEnvelopedEntryException.java @@ -20,7 +20,7 @@ import com.twitter.distributedlog.thrift.service.StatusCode; /** - * Exception thrown when encounter invalid enveloped entry + * Exception thrown when encounter invalid enveloped entry. */ public class InvalidEnvelopedEntryException extends DLException { diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InvalidStreamNameException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InvalidStreamNameException.java index a7d92023d..1e8f44597 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InvalidStreamNameException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/InvalidStreamNameException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when encountered invalid log stream. + */ public class InvalidStreamNameException extends DLException { private static final long serialVersionUID = 6393315766140568100L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LockCancelledException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LockCancelledException.java index 65e869208..98131ee97 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LockCancelledException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LockCancelledException.java @@ -17,6 +17,9 @@ */ package com.twitter.distributedlog.exceptions; +/** + * A lock is cancelled when waiting for locking a stream. + */ public class LockCancelledException extends LockingException { private static final long serialVersionUID = -148795017092861106L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LockingException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LockingException.java index 92ff8d6d4..326a1cd50 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LockingException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LockingException.java @@ -17,9 +17,11 @@ */ package com.twitter.distributedlog.exceptions; -import com.twitter.distributedlog.exceptions.DLException; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception when a log writer attempts to acquire a lock to write data to the stream. + */ public class LockingException extends DLException { private static final long serialVersionUID = -4960278188448464473L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogEmptyException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogEmptyException.java index 84813c1e6..7dcd644db 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogEmptyException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogEmptyException.java @@ -17,9 +17,11 @@ */ package com.twitter.distributedlog.exceptions; -import com.twitter.distributedlog.exceptions.DLException; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exceptions are thrown when attempt to read a log stream that doesn't have any records. + */ public class LogEmptyException extends DLException { private static final long serialVersionUID = -1106184127178002282L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogExistsException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogExistsException.java index 84ac10ece..e7a0d6d0e 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogExistsException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogExistsException.java @@ -20,7 +20,7 @@ import com.twitter.distributedlog.thrift.service.StatusCode; /** - * Log Already Exists + * Exception thrown on creating a log stream but the log stream already exists. */ public class LogExistsException extends DLException { private static final long serialVersionUID = 1794053581673506784L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogNotFoundException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogNotFoundException.java index 5fc843869..e2c93e8be 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogNotFoundException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogNotFoundException.java @@ -17,9 +17,11 @@ */ package com.twitter.distributedlog.exceptions; -import com.twitter.distributedlog.exceptions.DLException; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when a reader attempts to read a log stream that doesn't exist. + */ public class LogNotFoundException extends DLException { private static final long serialVersionUID = 871435700699403164L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogReadException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogReadException.java index a4c346b79..6b08f53f1 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogReadException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogReadException.java @@ -17,7 +17,6 @@ */ package com.twitter.distributedlog.exceptions; -import com.twitter.distributedlog.exceptions.DLException; import com.twitter.distributedlog.thrift.service.StatusCode; /** diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java index 0521133a4..76a1aa268 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java @@ -19,6 +19,11 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when attempting to write a record whose size is too larger. + * + *

The size limit of a log record is {@link com.twitter.distributedlog.LogRecord#MAX_LOGRECORD_SIZE}. + */ public class LogRecordTooLongException extends DLException { private static final long serialVersionUID = 2788274084603111386L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java index 76ab57315..cb62e7c9a 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when encountering metadata errors. + */ public class MetadataException extends DLException { private static final long serialVersionUID = 6683578078046016125L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java index 7c703e412..04edb01e8 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when a method is not implemented yet. + */ public class NotYetImplementedException extends DLException { private static final long serialVersionUID = -6002036746792556106L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java index ab46f6466..d564758c7 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java @@ -19,6 +19,12 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when the system is over capacity. + * + *

When this exception is received, the client (either writer or reader) should take actions to not + * overwhelm the system. For example, backoff sending any requests. + */ public class OverCapacityException extends DLException { private static final long serialVersionUID = -6398949404860680263L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java index 9bdef0eb0..78163336a 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java @@ -19,6 +19,11 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when a log writer attempt to acquire a lock. + * + *

It is typically thrown when the lock is already acquired by another writer. + */ public class OwnershipAcquireFailedException extends LockingException { private static final long serialVersionUID = 8176056926552748001L; private final String currentOwner; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java index 2876d3f62..84d9271a5 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a read request has been cancelled. + */ public class ReadCancelledException extends DLException { private static final long serialVersionUID = -6273430297547510262L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java index 4158c97b5..440d86e30 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java @@ -19,6 +19,11 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception indicates that the service is not available in one region. + * + *

The client should retry the other regions when encountering this exception. + */ public class RegionUnavailableException extends DLException { private static final long serialVersionUID = 5727337162533143957L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java index e4b61c44a..0a1e1c575 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a request has been denied at the server. + */ public class RequestDeniedException extends DLException { private static final long serialVersionUID = 7338220414584728216L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java index d35988c91..5224564d6 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a read request can be retried.. + */ public class RetryableReadException extends DLException { private static final long serialVersionUID = 2803207702150642330L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java index 7851c0b22..29e20d83e 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception indicates that the service is unavailable at the server side. + */ public class ServiceUnavailableException extends DLException { private static final long serialVersionUID = 6317900286881665746L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java index e44706ae8..6cac4689a 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when a log stream is not ready on server side for serving the write requests. + */ public class StreamNotReadyException extends DLException { private static final long serialVersionUID = 684211282036293028L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java index 1e23da00b..9872fdc39 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception thrown when a stream is not available for serving traffic. + */ public class StreamUnavailableException extends DLException { private static final long serialVersionUID = 684211282036993028L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java index bbee4e4dc..6ee405d55 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a server has been serving too many streams. + */ public class TooManyStreamsException extends OverCapacityException { private static final long serialVersionUID = -6391941401860180163L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java index 370b83e84..915525c2e 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * An exception is thrown when a log writer attempts to write a record with out-of-order transaction id. + */ public class TransactionIdOutOfOrderException extends DLException { private static final long serialVersionUID = -6239322552103630036L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java index ec26ad2c8..4454cd091 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * An {@code UnexpectedException} is thrown when encountering unexpected conditions. + */ public class UnexpectedException extends DLException { private static final long serialVersionUID = 903763128422774055L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java index 042c7dbea..47c361a4f 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java @@ -19,6 +19,9 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when found unsupported metadata version. + */ public class UnsupportedMetadataVersionException extends DLException { private static final long serialVersionUID = 4980892659955478446L; diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java index 33f11d40c..f3adac203 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java @@ -19,14 +19,17 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals when a write request is cancelled. + */ public class WriteCancelledException extends DLException { private static final long serialVersionUID = -1836146493496072122L; public WriteCancelledException(String stream, Throwable t) { super(StatusCode.WRITE_CANCELLED_EXCEPTION, - "Write cancelled on stream " + - stream + " due to an earlier error", t); + "Write cancelled on stream " + + stream + " due to an earlier error", t); } public WriteCancelledException(String stream, String reason) { @@ -36,7 +39,7 @@ public WriteCancelledException(String stream, String reason) { public WriteCancelledException(String stream) { super(StatusCode.WRITE_CANCELLED_EXCEPTION, - "Write cancelled on stream " + - stream + " due to an earlier error"); + "Write cancelled on stream " + + stream + " due to an earlier error"); } } diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java index 64714d7d7..77c18d431 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java @@ -19,13 +19,15 @@ import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * An exception on writing log records. + */ public class WriteException extends DLException { private static final long serialVersionUID = -1836146493446072122L; public WriteException(String stream, String transmitError) { super(StatusCode.WRITE_EXCEPTION, - "Write rejected because stream " + stream + " has encountered an error : " + - transmitError); + "Write rejected because stream " + stream + " has encountered an error : " + transmitError); } } diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/package-info.java new file mode 100644 index 000000000..ad027d860 --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +/** + * Defines exceptions used across distributedlog project. + */ +package com.twitter.distributedlog.exceptions; \ No newline at end of file diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java index 2637f8756..0f1753a8b 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java @@ -20,14 +20,13 @@ import org.apache.bookkeeper.stats.OpStatsLogger; /** - * Common interface for compression/decompression operations using different - * compression codecs. + * Common interface for compression/decompression operations using different compression codecs. */ public interface CompressionCodec { /** * Enum specifying the currently supported compression types. */ - public static enum Type { + enum Type { NONE, LZ4, UNKNOWN } diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java index 3acef6277..255278691 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java @@ -17,13 +17,16 @@ */ package com.twitter.distributedlog.io; +/** + * Utils for compression related operations. + */ public class CompressionUtils { - public final static String LZ4 = "lz4"; - public final static String NONE = "none"; + public static final String LZ4 = "lz4"; + public static final String NONE = "none"; - private static CompressionCodec identityCodec = new IdentityCompressionCodec(); - private static CompressionCodec lz4Codec = new LZ4CompressionCodec(); + private static final CompressionCodec IDENTITY_CODEC = new IdentityCompressionCodec(); + private static final CompressionCodec LZ4_CODEC = new LZ4CompressionCodec(); /** * Get a cached compression codec instance for the specified type. @@ -32,10 +35,10 @@ public class CompressionUtils { */ public static CompressionCodec getCompressionCodec(CompressionCodec.Type type) { if (type == CompressionCodec.Type.LZ4) { - return lz4Codec; + return LZ4_CODEC; } // No Compression - return identityCodec; + return IDENTITY_CODEC; } /** diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java index 4cc776284..39952c3a1 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java @@ -17,23 +17,26 @@ */ package com.twitter.distributedlog.io; -import java.util.Arrays; - -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Arrays; import org.apache.bookkeeper.stats.OpStatsLogger; +/** + * An identity compression codec implementation for {@link CompressionCodec}. + */ public class IdentityCompressionCodec implements CompressionCodec { @Override public byte[] compress(byte[] data, int offset, int length, OpStatsLogger compressionStat) { - Preconditions.checkNotNull(data); - Preconditions.checkArgument(length >= 0); + checkNotNull(data); + checkArgument(length >= 0); return Arrays.copyOfRange(data, offset, offset + length); } @Override public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger decompressionStat) { - Preconditions.checkNotNull(data); + checkNotNull(data); return Arrays.copyOfRange(data, offset, offset + length); } diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java index 2137452a6..12d6ac462 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java @@ -17,21 +17,22 @@ */ package com.twitter.distributedlog.io; -import java.util.concurrent.TimeUnit; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Preconditions; import com.google.common.base.Stopwatch; - +import java.util.concurrent.TimeUnit; import net.jpountz.lz4.LZ4Compressor; import net.jpountz.lz4.LZ4Exception; import net.jpountz.lz4.LZ4Factory; import net.jpountz.lz4.LZ4FastDecompressor; import net.jpountz.lz4.LZ4SafeDecompressor; - import org.apache.bookkeeper.stats.OpStatsLogger; /** - * All functions are thread safe. + * An {@code lz4} based {@link CompressionCodec} implementation. + * + *

All functions are thread safe. */ public class LZ4CompressionCodec implements CompressionCodec { @@ -50,10 +51,10 @@ public LZ4CompressionCodec() { @Override public byte[] compress(byte[] data, int offset, int length, OpStatsLogger compressionStat) { - Preconditions.checkNotNull(data); - Preconditions.checkArgument(offset >= 0 && offset < data.length); - Preconditions.checkArgument(length >= 0); - Preconditions.checkNotNull(compressionStat); + checkNotNull(data); + checkArgument(offset >= 0 && offset < data.length); + checkArgument(length >= 0); + checkNotNull(compressionStat); Stopwatch watch = Stopwatch.createStarted(); byte[] compressed = compressor.compress(data, offset, length); @@ -63,10 +64,10 @@ public byte[] compress(byte[] data, int offset, int length, OpStatsLogger compre @Override public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger decompressionStat) { - Preconditions.checkNotNull(data); - Preconditions.checkArgument(offset >= 0 && offset < data.length); - Preconditions.checkArgument(length >= 0); - Preconditions.checkNotNull(decompressionStat); + checkNotNull(data); + checkArgument(offset >= 0 && offset < data.length); + checkArgument(length >= 0); + checkNotNull(decompressionStat); Stopwatch watch = Stopwatch.createStarted(); // Assume that we have a compression ratio of 1/3. @@ -86,11 +87,11 @@ public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger deco // length parameter is ignored here because of the way the fastDecompressor works. public byte[] decompress(byte[] data, int offset, int length, int decompressedSize, OpStatsLogger decompressionStat) { - Preconditions.checkNotNull(data); - Preconditions.checkArgument(offset >= 0 && offset < data.length); - Preconditions.checkArgument(length >= 0); - Preconditions.checkArgument(decompressedSize >= 0); - Preconditions.checkNotNull(decompressionStat); + checkNotNull(data); + checkArgument(offset >= 0 && offset < data.length); + checkArgument(length >= 0); + checkArgument(decompressedSize >= 0); + checkNotNull(decompressionStat); Stopwatch watch = Stopwatch.createStarted(); byte[] decompressed = fastDecompressor.decompress(data, offset, decompressedSize); diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/package-info.java new file mode 100644 index 000000000..bbd9528e8 --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +/** + * I/O related utilities used across the project. + */ +package com.twitter.distributedlog.io; \ No newline at end of file diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/package-info.java new file mode 100644 index 000000000..8fc526d0a --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +/** + * Provides the core data structures used across multiple modules. + */ +package com.twitter.distributedlog; \ No newline at end of file diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java index adee084a0..07d9d269c 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java @@ -17,15 +17,18 @@ */ package com.twitter.distributedlog.util; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; +/** + * Utils for bit mask operations. + */ public class BitMaskUtils { /** * 1) Unset all bits where value in mask is set. * 2) Set these bits to value specified by newValue. * - * e.g. + *

e.g. * if oldValue = 1010, mask = 0011, newValue = 0001 * 1) 1010 -> 1000 * 2) 1000 -> 1001 @@ -36,19 +39,19 @@ public class BitMaskUtils { * @return updated value */ public static long set(long oldValue, long mask, long newValue) { - Preconditions.checkArgument(oldValue >= 0L && mask >= 0L && newValue >= 0L); + checkArgument(oldValue >= 0L && mask >= 0L && newValue >= 0L); return ((oldValue & (~mask)) | (newValue & mask)); } /** - * Get the bits where mask is 1 + * Get the bits where mask is 1. * * @param value value * @param mask mask of the value * @return the bit of the mask */ public static long get(long value, long mask) { - Preconditions.checkArgument(value >= 0L && mask >= 0L); + checkArgument(value >= 0L && mask >= 0L); return (value & mask); } } diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java index 0b084714f..bac5cdd0e 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java @@ -17,11 +17,10 @@ */ package com.twitter.distributedlog.util; -import java.util.zip.CRC32; +import static com.google.common.base.Charsets.UTF_8; import com.twitter.distributedlog.DLSN; - -import static com.google.common.base.Charsets.UTF_8; +import java.util.zip.CRC32; /** * With CRC embedded in the application, we have to keep track of per api crc. Ideally this diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/package-info.java new file mode 100644 index 000000000..f95e66619 --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +/** + * defines the utilities used across the project. + */ +package com.twitter.distributedlog.util; \ No newline at end of file diff --git a/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java b/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java index 373994b87..551d0ca54 100644 --- a/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java +++ b/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java @@ -17,9 +17,14 @@ */ package com.twitter.distributedlog; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import org.junit.Test; -import static org.junit.Assert.*; +/** + * Test Case for {@link DLSN}. + */ public class TestDLSN { @Test(timeout = 60000) diff --git a/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java b/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java index bc1e6273d..4a5fdacf4 100644 --- a/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java +++ b/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java @@ -17,6 +17,13 @@ */ package com.twitter.distributedlog; +import static com.google.common.base.Charsets.UTF_8; +import static com.twitter.distributedlog.LogRecord.MAX_LOGRECORD_SIZE; +import static com.twitter.distributedlog.LogRecordSet.HEADER_LEN; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import com.google.common.collect.Lists; import com.twitter.distributedlog.LogRecordSet.Reader; import com.twitter.distributedlog.LogRecordSet.Writer; @@ -25,18 +32,12 @@ import com.twitter.util.Await; import com.twitter.util.Future; import com.twitter.util.Promise; -import org.junit.Test; - import java.nio.ByteBuffer; import java.util.List; - -import static com.google.common.base.Charsets.UTF_8; -import static com.twitter.distributedlog.LogRecord.*; -import static com.twitter.distributedlog.LogRecordSet.*; -import static org.junit.Assert.*; +import org.junit.Test; /** - * Test Case for {@link LogRecordSet} + * Test Case for {@link LogRecordSet}. */ public class TestLogRecordSet { diff --git a/pom.xml b/pom.xml index 6441a26f5..c2773905f 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,7 @@ + distributedlog-build-tools distributedlog-protocol distributedlog-core distributedlog-client From 5dc4067e7fe1759c83ceee0ba6bf67e904b39ec3 Mon Sep 17 00:00:00 2001 From: Xi Liu Date: Tue, 20 Dec 2016 00:34:29 -0800 Subject: [PATCH 2/2] addressed comments --- .../src/main/resources/distributedlog/checkstyle.xml | 2 +- .../src/main/resources/ide/eclipse}/DL_formatter.xml | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {dev-support => distributedlog-build-tools/src/main/resources/ide/eclipse}/DL_formatter.xml (100%) diff --git a/distributedlog-build-tools/src/main/resources/distributedlog/checkstyle.xml b/distributedlog-build-tools/src/main/resources/distributedlog/checkstyle.xml index 45be45e16..e1117c89c 100644 --- a/distributedlog-build-tools/src/main/resources/distributedlog/checkstyle.xml +++ b/distributedlog-build-tools/src/main/resources/distributedlog/checkstyle.xml @@ -103,7 +103,7 @@ page at http://checkstyle.sourceforge.net/config.html --> - + diff --git a/dev-support/DL_formatter.xml b/distributedlog-build-tools/src/main/resources/ide/eclipse/DL_formatter.xml similarity index 100% rename from dev-support/DL_formatter.xml rename to distributedlog-build-tools/src/main/resources/ide/eclipse/DL_formatter.xml