Skip to content

Commit

Permalink
[SPARK-14011][CORE][SQL] Enable LineLength Java checkstyle rule
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?

[Spark Coding Style Guide](https://cwiki.apache.org/confluence/display/SPARK/Spark+Code+Style+Guide) has 100-character limit on lines, but it's disabled for Java since 11/09/15. This PR enables **LineLength** checkstyle again. To help that, this also introduces **RedundantImport** and **RedundantModifier**, too. The following is the diff on `checkstyle.xml`.

```xml
-        <!-- TODO: 11/09/15 disabled - the lengths are currently > 100 in many places -->
-        <!--
         <module name="LineLength">
             <property name="max" value="100"/>
             <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
         </module>
-        -->
         <module name="NoLineWrap"/>
         <module name="EmptyBlock">
             <property name="option" value="TEXT"/>
 -167,5 +164,7
         </module>
         <module name="CommentsIndentation"/>
         <module name="UnusedImports"/>
+        <module name="RedundantImport"/>
+        <module name="RedundantModifier"/>
```

## How was this patch tested?

Currently, `lint-java` is disabled in Jenkins. It needs a manual test.
After passing the Jenkins tests, `dev/lint-java` should passes locally.

Author: Dongjoon Hyun <[email protected]>

Closes apache#11831 from dongjoon-hyun/SPARK-14011.
  • Loading branch information
dongjoon-hyun authored and srowen committed Mar 21, 2016
1 parent e474088 commit 20fd254
Show file tree
Hide file tree
Showing 74 changed files with 579 additions and 505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@

/**
* Contains the context to create a {@link TransportServer}, {@link TransportClientFactory}, and to
* setup Netty Channel pipelines with a {@link org.apache.spark.network.server.TransportChannelHandler}.
* setup Netty Channel pipelines with a
* {@link org.apache.spark.network.server.TransportChannelHandler}.
*
* There are two communication protocols that the TransportClient provides, control-plane RPCs and
* data-plane "chunk fetching". The handling of the RPCs is performed outside of the scope of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.nio.ByteBuffer;

/**
* Callback for streaming data. Stream data will be offered to the {@link #onData(String, ByteBuffer)}
* method as it arrives. Once all the stream data is received, {@link #onComplete(String)} will be
* called.
* Callback for streaming data. Stream data will be offered to the
* {@link #onData(String, ByteBuffer)} method as it arrives. Once all the stream data is received,
* {@link #onComplete(String)} will be called.
* <p>
* The network library guarantees that a single thread will call these methods at a time, but
* different call may be made by different threads.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static class ClientPool {
TransportClient[] clients;
Object[] locks;

public ClientPool(int size) {
ClientPool(int size) {
clients = new TransportClient[size];
locks = new Object[size];
for (int i = 0; i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public interface Message extends Encodable {
boolean isBodyInFrame();

/** Preceding every serialized Message is its type, which allows us to deserialize it. */
public static enum Type implements Encodable {
enum Type implements Encodable {
ChunkFetchRequest(0), ChunkFetchSuccess(1), ChunkFetchFailure(2),
RpcRequest(3), RpcResponse(4), RpcFailure(5),
StreamRequest(6), StreamResponse(7), StreamFailure(8),
OneWayMessage(9), User(-1);

private final byte id;

private Type(int id) {
Type(int id) {
assert id < 128 : "Cannot have more than 128 message types";
this.id = (byte) id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.spark.network.protocol;

import org.apache.spark.network.protocol.Message;

/** Messages from the client to the server. */
public interface RequestMessage extends Message {
// token interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.spark.network.protocol;

import org.apache.spark.network.protocol.Message;

/** Messages from the server to the client. */
public interface ResponseMessage extends Message {
// token interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class SaslMessage extends AbstractMessage {

public final String appId;

public SaslMessage(String appId, byte[] message) {
SaslMessage(String appId, byte[] message) {
this(appId, Unpooled.wrappedBuffer(message));
}

public SaslMessage(String appId, ByteBuf message) {
SaslMessage(String appId, ByteBuf message) {
super(new NettyManagedBuffer(message), true);
this.appId = appId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.apache.spark.network.client.TransportClient;

/**
* StreamManager which allows registration of an Iterator&lt;ManagedBuffer&gt;, which are individually
* fetched as chunks by the client. Each registered buffer is one chunk.
* StreamManager which allows registration of an Iterator&lt;ManagedBuffer&gt;, which are
* individually fetched as chunks by the client. Each registered buffer is one chunk.
*/
public class OneForOneStreamManager extends StreamManager {
private final Logger logger = LoggerFactory.getLogger(OneForOneStreamManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
if (responseHandler.numOutstandingRequests() > 0) {
String address = NettyUtils.getRemoteAddress(ctx.channel());
logger.error("Connection to {} has been quiet for {} ms while there are outstanding " +
"requests. Assuming connection is dead; please adjust spark.network.timeout if this " +
"is wrong.", address, requestTimeoutNs / 1000 / 1000);
"requests. Assuming connection is dead; please adjust spark.network.timeout if " +
"this is wrong.", address, requestTimeoutNs / 1000 / 1000);
client.timeOut();
ctx.close();
} else if (closeIdleConnections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum ByteUnit {
TiB ((long) Math.pow(1024L, 4L)),
PiB ((long) Math.pow(1024L, 5L));

private ByteUnit(long multiplier) {
ByteUnit(long multiplier) {
this.multiplier = multiplier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import java.util.NoSuchElementException;

import org.apache.spark.network.util.ConfigProvider;

/** Uses System properties to obtain config values. */
public class SystemPropertyConfigProvider extends ConfigProvider {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private boolean feedInterceptor(ByteBuf buf) throws Exception {
return interceptor != null;
}

public static interface Interceptor {
public interface Interceptor {

/**
* Handles data received from the remote end.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.spark.network.sasl;

import java.lang.Override;
import java.nio.ByteBuffer;
import java.util.concurrent.ConcurrentHashMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public class ExternalShuffleBlockHandler extends RpcHandler {
final ExternalShuffleBlockResolver blockManager;
private final OneForOneStreamManager streamManager;

public ExternalShuffleBlockHandler(TransportConf conf, File registeredExecutorFile) throws IOException {
public ExternalShuffleBlockHandler(TransportConf conf, File registeredExecutorFile)
throws IOException {
this(new OneForOneStreamManager(),
new ExternalShuffleBlockResolver(conf, registeredExecutorFile));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ public static class StoreVersion {
public final int major;
public final int minor;

@JsonCreator public StoreVersion(@JsonProperty("major") int major, @JsonProperty("minor") int minor) {
@JsonCreator public StoreVersion(
@JsonProperty("major") int major,
@JsonProperty("minor") int minor) {
this.major = major;
this.minor = minor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class RetryingBlockFetcher {
* Used to initiate the first fetch for all blocks, and subsequently for retrying the fetch on any
* remaining blocks.
*/
public static interface BlockFetchStarter {
public interface BlockFetchStarter {
/**
* Creates a new BlockFetcher to fetch the given block ids which may do some synchronous
* bootstrapping followed by fully asynchronous block fetching.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public abstract class BlockTransferMessage implements Encodable {
protected abstract Type type();

/** Preceding every serialized message is its type, which allows us to deserialize it. */
public static enum Type {
public enum Type {
OPEN_BLOCKS(0), UPLOAD_BLOCK(1), REGISTER_EXECUTOR(2), STREAM_HANDLE(3), REGISTER_DRIVER(4),
HEARTBEAT(5);

private final byte id;

private Type(int id) {
Type(int id) {
assert id < 128 : "Cannot have more than 128 message types";
this.id = (byte) id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public void onBlockFetchFailure(String blockId, Throwable t) {
};

String[] blockIds = { "shuffle_2_3_4", "shuffle_6_7_8" };
OneForOneBlockFetcher fetcher = new OneForOneBlockFetcher(client1, "app-2", "0", blockIds, listener);
OneForOneBlockFetcher fetcher =
new OneForOneBlockFetcher(client1, "app-2", "0", blockIds, listener);
fetcher.start();
blockFetchLatch.await();
checkSecurityException(exception.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public void testBadMessages() {
// pass
}

ByteBuffer unexpectedMsg = new UploadBlock("a", "e", "b", new byte[1], new byte[2]).toByteBuffer();
ByteBuffer unexpectedMsg = new UploadBlock("a", "e", "b", new byte[1],
new byte[2]).toByteBuffer();
try {
handler.receive(client, unexpectedMsg, callback);
fail("Should have thrown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Murmur3_x86_32 {

private final int seed;

public Murmur3_x86_32(int seed) {
Murmur3_x86_32(int seed) {
this.seed = seed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public static boolean anySet(Object baseObject, long baseOffset, long bitSetWidt
* To iterate over the true bits in a BitSet, use the following loop:
* <pre>
* <code>
* for (long i = bs.nextSetBit(0, sizeInWords); i &gt;= 0; i = bs.nextSetBit(i + 1, sizeInWords)) {
* for (long i = bs.nextSetBit(0, sizeInWords); i &gt;= 0;
* i = bs.nextSetBit(i + 1, sizeInWords)) {
* // operate on index i here
* }
* </code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ public final <K, V> JavaPairRDD<K, V> union(JavaPairRDD<K, V>... rdds) {
// These methods take separate "first" and "rest" elements to avoid having the same type erasure
public abstract <T> JavaRDD<T> union(JavaRDD<T> first, List<JavaRDD<T>> rest);
public abstract JavaDoubleRDD union(JavaDoubleRDD first, List<JavaDoubleRDD> rest);
public abstract <K, V> JavaPairRDD<K, V> union(JavaPairRDD<K, V> first, List<JavaPairRDD<K, V>> rest);
public abstract <K, V> JavaPairRDD<K, V> union(JavaPairRDD<K, V> first, List<JavaPairRDD<K, V>>
rest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
* A function that returns Doubles, and can be used to construct DoubleRDDs.
*/
public interface DoubleFunction<T> extends Serializable {
public double call(T t) throws Exception;
double call(T t) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
* A two-argument function that takes arguments of type T1 and T2 and returns an R.
*/
public interface Function2<T1, T2, R> extends Serializable {
public R call(T1 v1, T2 v2) throws Exception;
R call(T1 v1, T2 v2) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
* A three-argument function that takes arguments of type T1, T2 and T3 and returns an R.
*/
public interface Function3<T1, T2, T3, R> extends Serializable {
public R call(T1 v1, T2 v2, T3 v3) throws Exception;
R call(T1 v1, T2 v2, T3 v3) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
* construct PairRDDs.
*/
public interface PairFunction<T, K, V> extends Serializable {
public Tuple2<K, V> call(T t) throws Exception;
Tuple2<K, V> call(T t) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public class TaskMemoryManager {

/**
* Maximum supported data page size (in bytes). In principle, the maximum addressable page size is
* (1L &lt;&lt; OFFSET_BITS) bytes, which is 2+ petabytes. However, the on-heap allocator's maximum page
* size is limited by the maximum amount of data that can be stored in a long[] array, which is
* (2^32 - 1) * 8 bytes (or 16 gigabytes). Therefore, we cap this at 16 gigabytes.
* (1L &lt;&lt; OFFSET_BITS) bytes, which is 2+ petabytes. However, the on-heap allocator's
* maximum page size is limited by the maximum amount of data that can be stored in a long[]
* array, which is (2^32 - 1) * 8 bytes (or 16 gigabytes). Therefore, we cap this at 16 gigabytes.
*/
public static final long MAXIMUM_PAGE_SIZE_BYTES = ((1L << 31) - 1) * 8L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class BypassMergeSortShuffleWriter<K, V> extends ShuffleWriter<K, V> {
*/
private boolean stopping = false;

public BypassMergeSortShuffleWriter(
BypassMergeSortShuffleWriter(
BlockManager blockManager,
IndexShuffleBlockResolver shuffleBlockResolver,
BypassMergeSortShuffleHandle<K, V> handle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ final class ShuffleExternalSorter extends MemoryConsumer {
@Nullable private MemoryBlock currentPage = null;
private long pageCursor = -1;

public ShuffleExternalSorter(
ShuffleExternalSorter(
TaskMemoryManager memoryManager,
BlockManager blockManager,
TaskContext taskContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public int compare(PackedRecordPointer left, PackedRecordPointer right) {
*/
private int pos = 0;

public ShuffleInMemorySorter(MemoryConsumer consumer, int initialSize) {
ShuffleInMemorySorter(MemoryConsumer consumer, int initialSize) {
this.consumer = consumer;
assert (initialSize > 0);
this.array = consumer.allocateArray(initialSize);
Expand Down Expand Up @@ -122,7 +122,7 @@ public static final class ShuffleSorterIterator {
final PackedRecordPointer packedRecordPointer = new PackedRecordPointer();
private int position = 0;

public ShuffleSorterIterator(int numRecords, LongArray pointerArray) {
ShuffleSorterIterator(int numRecords, LongArray pointerArray) {
this.numRecords = numRecords;
this.pointerArray = pointerArray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class SpillInfo {
final File file;
final TempShuffleBlockId blockId;

public SpillInfo(int numPartitions, File file, TempShuffleBlockId blockId) {
SpillInfo(int numPartitions, File file, TempShuffleBlockId blockId) {
this.partitionLengths = new long[numPartitions];
this.file = file;
this.blockId = blockId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.apache.spark.scheduler.MapStatus;
import org.apache.spark.scheduler.MapStatus$;
import org.apache.spark.serializer.SerializationStream;
import org.apache.spark.serializer.Serializer;
import org.apache.spark.serializer.SerializerInstance;
import org.apache.spark.shuffle.IndexShuffleBlockResolver;
import org.apache.spark.shuffle.ShuffleWriter;
Expand Down Expand Up @@ -82,7 +81,7 @@ public class UnsafeShuffleWriter<K, V> extends ShuffleWriter<K, V> {

/** Subclass of ByteArrayOutputStream that exposes `buf` directly. */
private static final class MyByteArrayOutputStream extends ByteArrayOutputStream {
public MyByteArrayOutputStream(int size) { super(size); }
MyByteArrayOutputStream(int size) { super(size); }
public byte[] getBuf() { return buf; }
}

Expand All @@ -108,7 +107,8 @@ public UnsafeShuffleWriter(
if (numPartitions > SortShuffleManager.MAX_SHUFFLE_OUTPUT_PARTITIONS_FOR_SERIALIZED_MODE()) {
throw new IllegalArgumentException(
"UnsafeShuffleWriter can only be used for shuffles with at most " +
SortShuffleManager.MAX_SHUFFLE_OUTPUT_PARTITIONS_FOR_SERIALIZED_MODE() + " reduce partitions");
SortShuffleManager.MAX_SHUFFLE_OUTPUT_PARTITIONS_FOR_SERIALIZED_MODE() +
" reduce partitions");
}
this.blockManager = blockManager;
this.shuffleBlockResolver = shuffleBlockResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum TaskSorting {
DECREASING_RUNTIME("-runtime");

private final Set<String> alternateNames;
private TaskSorting(String... names) {
TaskSorting(String... names) {
alternateNames = new HashSet<>();
for (String n: names) {
alternateNames.add(n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public boolean putNewKey(Object keyBase, long keyOffset, int keyLength,
offset += keyLength;
Platform.copyMemory(valueBase, valueOffset, base, offset, valueLength);

// --- Update bookkeeping data structures -----------------------------------------------------
// --- Update bookkeeping data structures ----------------------------------------------------
offset = currentPage.getBaseOffset();
Platform.putInt(base, offset, Platform.getInt(base, offset) + 1);
pageCursor += recordLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class SpillableIterator extends UnsafeSorterIterator {
private boolean loaded = false;
private int numRecords = 0;

public SpillableIterator(UnsafeInMemorySorter.SortedIterator inMemIterator) {
SpillableIterator(UnsafeInMemorySorter.SortedIterator inMemIterator) {
this.upstream = inMemIterator;
this.numRecords = inMemIterator.getNumRecords();
}
Expand Down Expand Up @@ -567,7 +567,7 @@ static class ChainedIterator extends UnsafeSorterIterator {
private UnsafeSorterIterator current;
private int numRecords;

public ChainedIterator(Queue<UnsafeSorterIterator> iterators) {
ChainedIterator(Queue<UnsafeSorterIterator> iterators) {
assert iterators.size() > 0;
this.numRecords = 0;
for (UnsafeSorterIterator iter: iterators) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public RecordPointerAndKeyPrefix newKey() {
}

@Override
public RecordPointerAndKeyPrefix getKey(LongArray data, int pos, RecordPointerAndKeyPrefix reuse) {
public RecordPointerAndKeyPrefix getKey(LongArray data, int pos,
RecordPointerAndKeyPrefix reuse) {
reuse.recordPointer = data.get(pos * 2);
reuse.keyPrefix = data.get(pos * 2 + 1);
return reuse;
Expand Down
Loading

0 comments on commit 20fd254

Please sign in to comment.