http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java index 8171ac1..53d0a9b 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java @@ -23,14 +23,29 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + package org.apache.kudu.client; +import static com.google.common.base.Preconditions.checkArgument; +import static org.apache.kudu.tserver.Tserver.NewScanRequestPB; +import static org.apache.kudu.tserver.Tserver.ScanRequestPB; +import static org.apache.kudu.tserver.Tserver.ScanResponsePB; +import static org.apache.kudu.tserver.Tserver.TabletServerErrorPB; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + import com.google.common.collect.ImmutableList; import com.google.protobuf.Message; import com.google.protobuf.ZeroCopyLiteralByteString; import com.stumbleupon.async.Callback; import com.stumbleupon.async.Deferred; import org.jboss.netty.buffer.ChannelBuffer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.kudu.ColumnSchema; import org.apache.kudu.Common; import org.apache.kudu.Schema; @@ -38,19 +53,6 @@ import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.annotations.InterfaceStability; import org.apache.kudu.tserver.Tserver; import org.apache.kudu.util.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import static com.google.common.base.Preconditions.checkArgument; -import static org.apache.kudu.tserver.Tserver.NewScanRequestPB; -import static org.apache.kudu.tserver.Tserver.ScanRequestPB; -import static org.apache.kudu.tserver.Tserver.ScanResponsePB; -import static org.apache.kudu.tserver.Tserver.TabletServerErrorPB; /** * Creates a scanner to read data from Kudu. @@ -371,11 +373,11 @@ public final class AsyncKuduScanner { new Callback<Deferred<RowResultIterator>, Response>() { @Override public Deferred<RowResultIterator> call(Response resp) throws Exception { - if (!resp.more || resp.scanner_id == null) { + if (!resp.more || resp.scannerId == null) { scanFinished(); return Deferred.fromResult(resp.data); // there might be data to return } - scannerId = resp.scanner_id; + scannerId = resp.scannerId; sequenceId++; hasMore = resp.more; if (LOG.isDebugEnabled()) { @@ -383,6 +385,7 @@ public final class AsyncKuduScanner { } return Deferred.fromResult(resp.data); } + public String toString() { return "scanner opened"; } @@ -412,6 +415,7 @@ public final class AsyncKuduScanner { return Deferred.fromError(e); // Let the error propogate. } } + public String toString() { return "open scanner errback"; } @@ -425,7 +429,7 @@ public final class AsyncKuduScanner { return prefetcherDeferred; } final Deferred<RowResultIterator> d = - client.scanNextRows(this).addCallbacks(got_next_row, nextRowErrback()); + client.scanNextRows(this).addCallbacks(gotNextRow, nextRowErrback()); if (prefetching) { d.chain(new Deferred<RowResultIterator>().addCallback(prefetch)); } @@ -437,8 +441,8 @@ public final class AsyncKuduScanner { @Override public RowResultIterator call(RowResultIterator arg) throws Exception { if (hasMoreRows()) { - prefetcherDeferred = client.scanNextRows(AsyncKuduScanner.this).addCallbacks - (got_next_row, nextRowErrback()); + prefetcherDeferred = client.scanNextRows(AsyncKuduScanner.this) + .addCallbacks(gotNextRow, nextRowErrback()); } return null; } @@ -449,7 +453,7 @@ public final class AsyncKuduScanner { * This returns an {@code ArrayList<ArrayList<KeyValue>>} (possibly inside a * deferred one). */ - private final Callback<RowResultIterator, Response> got_next_row = + private final Callback<RowResultIterator, Response> gotNextRow = new Callback<RowResultIterator, Response>() { public RowResultIterator call(final Response resp) { if (!resp.more) { // We're done scanning this tablet. @@ -461,6 +465,7 @@ public final class AsyncKuduScanner { //LOG.info("Scan.next is returning rows: " + resp.data.getNumRows()); return resp.data; } + public String toString() { return "get nextRows response"; } @@ -478,6 +483,7 @@ public final class AsyncKuduScanner { invalidate(); // If there was an error, don't assume we're still OK. return error; // Let the error propagate. } + public String toString() { return "NextRow errback"; } @@ -516,7 +522,7 @@ public final class AsyncKuduScanner { return Deferred.fromResult(null); } final Deferred<RowResultIterator> d = - client.closeScanner(this).addCallback(closedCallback()); // TODO errBack ? + client.closeScanner(this).addCallback(closedCallback()); // TODO errBack ? return d; } @@ -526,13 +532,14 @@ public final class AsyncKuduScanner { public RowResultIterator call(Response response) { closed = true; if (LOG.isDebugEnabled()) { - LOG.debug("Scanner " + Bytes.pretty(scannerId) + " closed on " - + tablet); + LOG.debug("Scanner " + Bytes.pretty(scannerId) + " closed on " + + tablet); } tablet = null; scannerId = "client debug closed".getBytes(); // Make debugging easier. return response == null ? null : response.data; } + public String toString() { return "scanner closed"; } @@ -621,7 +628,7 @@ public final class AsyncKuduScanner { */ static final class Response { /** The ID associated with the scanner that issued the request. */ - private final byte[] scanner_id; + private final byte[] scannerId; /** The actual payload of the response. */ private final RowResultIterator data; @@ -632,17 +639,17 @@ public final class AsyncKuduScanner { */ private final boolean more; - Response(final byte[] scanner_id, + Response(final byte[] scannerId, final RowResultIterator data, final boolean more) { - this.scanner_id = scanner_id; + this.scannerId = scannerId; this.data = data; this.more = more; } public String toString() { - return "AsyncKuduScanner$Response(scannerId=" + Bytes.pretty(scanner_id) - + ", data=" + data + ", more=" + more + ") "; + return "AsyncKuduScanner$Response(scannerId=" + Bytes.pretty(scannerId) + + ", data=" + data + ", more=" + more + ") "; } } @@ -666,7 +673,9 @@ public final class AsyncKuduScanner { } @Override - String serviceName() { return TABLET_SERVER_SERVICE_NAME; } + String serviceName() { + return TABLET_SERVER_SERVICE_NAME; + } @Override String method() { @@ -710,7 +719,7 @@ public final class AsyncKuduScanner { // if the mode is set to read on snapshot sent the snapshot timestamp if (AsyncKuduScanner.this.getReadMode() == ReadMode.READ_AT_SNAPSHOT && - AsyncKuduScanner.this.getSnapshotTimestamp() != AsyncKuduClient.NO_TIMESTAMP) { + AsyncKuduScanner.this.getSnapshotTimestamp() != AsyncKuduClient.NO_TIMESTAMP) { newBuilder.setSnapTimestamp(AsyncKuduScanner.this.getSnapshotTimestamp()); } @@ -739,6 +748,9 @@ public final class AsyncKuduScanner { builder.setScannerId(ZeroCopyLiteralByteString.wrap(scannerId)) .setBatchSizeBytes(0) .setCloseScanner(true); + break; + default: + throw new RuntimeException("unreachable!"); } ScanRequestPB request = builder.build(); @@ -774,9 +786,9 @@ public final class AsyncKuduScanner { boolean hasMore = resp.getHasMoreResults(); if (id.length != 0 && scannerId != null && !Bytes.equals(scannerId, id)) { - Status statusIllegalState = Status.IllegalState("Scan RPC response was for scanner" - + " ID " + Bytes.pretty(id) + " but we expected " - + Bytes.pretty(scannerId)); + Status statusIllegalState = Status.IllegalState("Scan RPC response was for scanner" + + " ID " + Bytes.pretty(id) + " but we expected " + + Bytes.pretty(scannerId)); throw new NonRecoverableException(statusIllegalState); } Response response = new Response(id, iterator, hasMore); @@ -787,9 +799,9 @@ public final class AsyncKuduScanner { } public String toString() { - return "ScanRequest(scannerId=" + Bytes.pretty(scannerId) - + (tablet != null? ", tabletSlice=" + tablet.getTabletId() : "") - + ", attempt=" + attempt + ", " + super.toString() + ")"; + return "ScanRequest(scannerId=" + Bytes.pretty(scannerId) + + (tablet != null ? ", tabletSlice=" + tablet.getTabletId() : "") + + ", attempt=" + attempt + ", " + super.toString() + ")"; } @Override
http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduSession.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduSession.java b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduSession.java index b8b3ea1..ac847fc 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduSession.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduSession.java @@ -14,8 +14,23 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import static org.apache.kudu.client.ExternalConsistencyMode.CLIENT_PROPAGATED; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import javax.annotation.concurrent.GuardedBy; +import javax.annotation.concurrent.NotThreadSafe; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; @@ -23,28 +38,15 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Range; import com.stumbleupon.async.Callback; import com.stumbleupon.async.Deferred; -import org.apache.kudu.annotations.InterfaceAudience; -import org.apache.kudu.annotations.InterfaceStability; -import org.apache.kudu.util.AsyncUtil; -import org.apache.kudu.util.Slice; import org.jboss.netty.util.Timeout; import org.jboss.netty.util.TimerTask; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.concurrent.GuardedBy; -import javax.annotation.concurrent.NotThreadSafe; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -import static org.apache.kudu.client.ExternalConsistencyMode.CLIENT_PROPAGATED; +import org.apache.kudu.annotations.InterfaceAudience; +import org.apache.kudu.annotations.InterfaceStability; +import org.apache.kudu.util.AsyncUtil; +import org.apache.kudu.util.Slice; /** * A AsyncKuduSession belongs to a specific AsyncKuduClient, and represents a context in @@ -190,8 +192,8 @@ public class AsyncKuduSession implements SessionConfiguration { @Override public void setExternalConsistencyMode(ExternalConsistencyMode consistencyMode) { if (hasPendingOperations()) { - throw new IllegalArgumentException("Cannot change consistency mode " - + "when writes are buffered"); + throw new IllegalArgumentException("Cannot change consistency mode " + + "when writes are buffered"); } this.consistencyMode = consistencyMode; } @@ -311,8 +313,10 @@ public class AsyncKuduSession implements SessionConfiguration { } @Override - public Void call(Object _void) throws Exception { - if (lookupsOutstanding.decrementAndGet() != 0) return null; + public Void call(Object unused) throws Exception { + if (lookupsOutstanding.decrementAndGet() != 0) { + return null; + } // The final tablet lookup is complete. Batch all of the buffered // operations into their respective tablet, and then send the batches. @@ -407,12 +411,12 @@ public class AsyncKuduSession implements SessionConfiguration { doFlush(buffer); return AsyncUtil.addBothDeferring(nonActiveBufferFlush, - new Callback<Deferred<List<OperationResponse>>, Object>() { - @Override - public Deferred<List<OperationResponse>> call(Object arg) { - return activeBufferFlush; - } - }); + new Callback<Deferred<List<OperationResponse>>, Object>() { + @Override + public Deferred<List<OperationResponse>> call(Object arg) { + return activeBufferFlush; + } + }); } /** @@ -447,6 +451,7 @@ public class AsyncKuduSession implements SessionConfiguration { List<BatchResponse>> { private static final ConvertBatchToListOfResponsesCB INSTANCE = new ConvertBatchToListOfResponsesCB(); + @Override public List<OperationResponse> call(List<BatchResponse> batchResponses) throws Exception { // First compute the size of the union of all the lists so that we don't trigger expensive @@ -463,10 +468,12 @@ public class AsyncKuduSession implements SessionConfiguration { return responses; } + @Override public String toString() { return "ConvertBatchToListOfResponsesCB"; } + public static ConvertBatchToListOfResponsesCB getInstance() { return INSTANCE; } @@ -633,7 +640,7 @@ public class AsyncKuduSession implements SessionConfiguration { // Both buffers are either flushing or inactive. return AsyncUtil.addBothDeferring(notificationA, new Callback<Deferred<Void>, Object>() { @Override - public Deferred<Void> call(Object _obj) throws Exception { + public Deferred<Void> call(Object obj) throws Exception { return notificationB; } }); @@ -708,6 +715,7 @@ public class AsyncKuduSession implements SessionConfiguration { // passed to ConvertBatchToListOfResponsesCB. return handleKuduException ? new BatchResponse(responses) : e; } + @Override public String toString() { return "apply batch error response"; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/Batch.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/Batch.java b/java/kudu-client/src/main/java/org/apache/kudu/client/Batch.java index 0f86a42..d50aed7 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/Batch.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/Batch.java @@ -14,18 +14,19 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package org.apache.kudu.client; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.MoreObjects; -import com.google.protobuf.Message; -import com.google.protobuf.ZeroCopyLiteralByteString; +package org.apache.kudu.client; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.MoreObjects; +import com.google.protobuf.Message; +import com.google.protobuf.ZeroCopyLiteralByteString; import org.jboss.netty.buffer.ChannelBuffer; + import org.apache.kudu.WireProtocol; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.client.Statistics.Statistic; @@ -87,7 +88,8 @@ class Batch extends KuduRpc<BatchResponse> { @Override ChannelBuffer serialize(Message header) { - final Tserver.WriteRequestPB.Builder builder = Operation.createAndFillWriteRequestPB(operations); + final Tserver.WriteRequestPB.Builder builder = + Operation.createAndFillWriteRequestPB(operations); rowOperationsSizeBytes = builder.getRowOperations().getRows().size() + builder.getRowOperations().getIndirectData().size(); builder.setTabletId(ZeroCopyLiteralByteString.wrap(getTablet().getTabletIdAsBytes())); @@ -133,12 +135,14 @@ class Batch extends KuduRpc<BatchResponse> { try { Thread.sleep(injectedlatencyMs); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } return new Pair<BatchResponse, Object>(response, injectedError); } - return new Pair<BatchResponse, Object>(response, builder.hasError() ? builder.getError() : null); + return new Pair<BatchResponse, Object>(response, + builder.hasError() ? builder.getError() : null); } @Override http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/BatchResponse.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/BatchResponse.java b/java/kudu-client/src/main/java/org/apache/kudu/client/BatchResponse.java index 8dd564a..55cb29f 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/BatchResponse.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/BatchResponse.java @@ -14,14 +14,15 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package org.apache.kudu.client; -import com.google.common.collect.ImmutableList; +package org.apache.kudu.client; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import com.google.common.collect.ImmutableList; + import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.tserver.Tserver; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/Bytes.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/Bytes.java b/java/kudu-client/src/main/java/org/apache/kudu/client/Bytes.java index 9f2d021..1e035fa 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/Bytes.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/Bytes.java @@ -23,15 +23,8 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package org.apache.kudu.client; -import com.google.common.io.BaseEncoding; -import com.google.protobuf.ByteString; -import com.google.protobuf.ZeroCopyLiteralByteString; -import org.apache.kudu.annotations.InterfaceAudience; -import org.apache.kudu.util.Slice; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.util.CharsetUtil; +package org.apache.kudu.client; import java.io.DataInput; import java.io.DataOutput; @@ -45,6 +38,15 @@ import java.util.Arrays; import java.util.BitSet; import java.util.Comparator; +import com.google.common.io.BaseEncoding; +import com.google.protobuf.ByteString; +import com.google.protobuf.ZeroCopyLiteralByteString; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.util.CharsetUtil; + +import org.apache.kudu.annotations.InterfaceAudience; +import org.apache.kudu.util.Slice; + /** * Helper functions to manipulate byte arrays. */ @@ -288,10 +290,10 @@ public final class Bytes { * @throws IndexOutOfBoundsException if the byte array is too small. */ public static int getInt(final byte[] b, final int offset) { - return (b[offset + 0] & 0xFF) << 0 - | (b[offset + 1] & 0xFF) << 8 - | (b[offset + 2] & 0xFF) << 16 - | (b[offset + 3] & 0xFF) << 24; + return (b[offset + 0] & 0xFF) << 0 | + (b[offset + 1] & 0xFF) << 8 | + (b[offset + 2] & 0xFF) << 16 | + (b[offset + 3] & 0xFF) << 24; } /** @@ -366,27 +368,27 @@ public final class Bytes { } public static void putVarInt32(final ByteBuffer b, final int v) { - int B = 128; - if (v < (1<<7)) { + int bee = 128; + if (v < (1 << 7)) { b.put((byte)v); - } else if (v < (1<<14)) { - b.put((byte)(v | B)); - b.put((byte)((v>>7) | B)); - } else if (v < (1<<21)) { - b.put((byte)(v | B)); - b.put((byte)((v>>7) | B)); - b.put((byte)(v>>14)); - } else if (v < (1<<28)) { - b.put((byte)(v | B)); - b.put((byte)((v>>7) | B)); - b.put((byte)((v>>14) | B)); - b.put((byte)(v>>21)); + } else if (v < (1 << 14)) { + b.put((byte)(v | bee)); + b.put((byte)((v >> 7) | bee)); + } else if (v < (1 << 21)) { + b.put((byte)(v | bee)); + b.put((byte)((v >> 7) | bee)); + b.put((byte)(v >> 14)); + } else if (v < (1 << 28)) { + b.put((byte)(v | bee)); + b.put((byte)((v >> 7) | bee)); + b.put((byte)((v >> 14) | bee)); + b.put((byte)(v >> 21)); } else { - b.put((byte)(v | B)); - b.put((byte)((v>>7) | B)); - b.put((byte)((v>>14) | B)); - b.put((byte)((v>>21) | B)); - b.put((byte)(v>>28)); + b.put((byte)(v | bee)); + b.put((byte)((v >> 7) | bee)); + b.put((byte)((v >> 14) | bee)); + b.put((byte)((v >> 21) | bee)); + b.put((byte)(v >> 28)); } } @@ -421,14 +423,14 @@ public final class Bytes { if (b >= 0) { return result; } - throw new IllegalArgumentException("Not a 32 bit varint: " + result - + " (5th byte: " + b + ")"); + throw new IllegalArgumentException("Not a 32 bit varint: " + result + + " (5th byte: " + b + ")"); } public static byte[] fromBoolean(final boolean n) { - final byte[] b = new byte[1]; - b[0] = (byte) (n ? 1 : 0); - return b; + final byte[] b = new byte[1]; + b[0] = (byte) (n ? 1 : 0); + return b; } /** @@ -472,7 +474,7 @@ public final class Bytes { */ public static BigInteger getUnsignedLong(final byte[] b, final int offset) { long l = getLong(b, offset); - BigInteger bi = new BigInteger(l+""); + BigInteger bi = new BigInteger(l + ""); if (bi.compareTo(BigInteger.ZERO) < 0) { bi = bi.add(TWO_COMPL_REF); } @@ -497,14 +499,14 @@ public final class Bytes { * @throws IndexOutOfBoundsException if the byte array is too small. */ public static long getLong(final byte[] b, final int offset) { - return (b[offset + 0] & 0xFFL) << 0 - | (b[offset + 1] & 0xFFL) << 8 - | (b[offset + 2] & 0xFFL) << 16 - | (b[offset + 3] & 0xFFL) << 24 - | (b[offset + 4] & 0xFFL) << 32 - | (b[offset + 5] & 0xFFL) << 40 - | (b[offset + 6] & 0xFFL) << 48 - | (b[offset + 7] & 0xFFL) << 56; + return (b[offset + 0] & 0xFFL) << 0 | + (b[offset + 1] & 0xFFL) << 8 | + (b[offset + 2] & 0xFFL) << 16 | + (b[offset + 3] & 0xFFL) << 24 | + (b[offset + 4] & 0xFFL) << 32 | + (b[offset + 5] & 0xFFL) << 40 | + (b[offset + 6] & 0xFFL) << 48 | + (b[offset + 7] & 0xFFL) << 56; } /** @@ -693,7 +695,7 @@ public final class Bytes { public static byte[] get(final ByteString buf) { return ZeroCopyLiteralByteString.zeroCopyGetBytes(buf); } - + // CHECKSTYLE:OFF /** Transforms a string into an UTF-8 encoded byte array. */ public static byte[] UTF8(final String s) { return s.getBytes(CharsetUtil.UTF_8); @@ -703,7 +705,7 @@ public final class Bytes { public static byte[] ISO88591(final String s) { return s.getBytes(CharsetUtil.ISO_8859_1); } - + // CHECKSTYLE:ON // ---------------------------- // // Pretty-printing byte arrays. // // ---------------------------- // @@ -792,6 +794,36 @@ public final class Bytes { } /** + * Pretty-prints all the bytes of a buffer into a human-readable string. + * @param buf The (possibly {@code null}) buffer to pretty-print. + * @return The buffer in a pretty-printed string. + */ + public static String pretty(final ChannelBuffer buf) { + if (buf == null) { + return "null"; + } + byte[] array; + try { + if (buf.getClass() != ReplayingDecoderBuffer) { + array = buf.array(); + } else if (RDB_buf != null) { // Netty 3.5.1 and above. + array = ((ChannelBuffer) RDB_buf.invoke(buf)).array(); + } else { // Netty 3.5.0 and before. + final ChannelBuffer wrapped_buf = (ChannelBuffer) RDB_buffer.get(buf); + array = wrapped_buf.array(); + } + } catch (UnsupportedOperationException e) { + return "(failed to extract content of buffer of type " + + buf.getClass().getName() + ')'; + } catch (IllegalAccessException e) { + throw new AssertionError("Should not happen: " + e); + } catch (InvocationTargetException e) { + throw new AssertionError("Should not happen: " + e); + } + return pretty(array); + } + + /** * Convert a byte array to a hex encoded string. * @param bytes the bytes to encode * @return the hex encoded bytes @@ -826,10 +858,11 @@ public final class Bytes { private static final Class<?> ReplayingDecoderBuffer; private static final Field RDB_buffer; // For Netty 3.5.0 and before. private static final Method RDB_buf; // For Netty 3.5.1 and above. + static { try { - ReplayingDecoderBuffer = Class.forName("org.jboss.netty.handler.codec." - + "replay.ReplayingDecoderBuffer"); + ReplayingDecoderBuffer = Class.forName("org.jboss.netty.handler.codec." + + "replay.ReplayingDecoderBuffer"); Field field = null; try { field = ReplayingDecoderBuffer.getDeclaredField("buffer"); @@ -849,36 +882,6 @@ public final class Bytes { } } - /** - * Pretty-prints all the bytes of a buffer into a human-readable string. - * @param buf The (possibly {@code null}) buffer to pretty-print. - * @return The buffer in a pretty-printed string. - */ - public static String pretty(final ChannelBuffer buf) { - if (buf == null) { - return "null"; - } - byte[] array; - try { - if (buf.getClass() != ReplayingDecoderBuffer) { - array = buf.array(); - } else if (RDB_buf != null) { // Netty 3.5.1 and above. - array = ((ChannelBuffer) RDB_buf.invoke(buf)).array(); - } else { // Netty 3.5.0 and before. - final ChannelBuffer wrapped_buf = (ChannelBuffer) RDB_buffer.get(buf); - array = wrapped_buf.array(); - } - } catch (UnsupportedOperationException e) { - return "(failed to extract content of buffer of type " - + buf.getClass().getName() + ')'; - } catch (IllegalAccessException e) { - throw new AssertionError("Should not happen: " + e); - } catch (InvocationTargetException e) { - throw new AssertionError("Should not happen: " + e); - } - return pretty(array); - } - // ---------------------- // // Comparing byte arrays. // // ---------------------- // http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/CallResponse.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/CallResponse.java b/java/kudu-client/src/main/java/org/apache/kudu/client/CallResponse.java index 631cc66..71b1a8f 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/CallResponse.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/CallResponse.java @@ -14,16 +14,17 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import java.util.List; +import org.jboss.netty.buffer.ChannelBuffer; + import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.rpc.RpcHeader; import org.apache.kudu.util.Slice; -import org.jboss.netty.buffer.ChannelBuffer; - /** * This class handles information received from an RPC response, providing * access to sidecars and decoded protobufs from the message. @@ -74,7 +75,9 @@ final class CallResponse { /** * @return the total response size */ - public int getTotalResponseSize() { return this.totalResponseSize; } + public int getTotalResponseSize() { + return this.totalResponseSize; + } /** * @return A slice pointing to the section of the packet reserved for the main @@ -90,9 +93,9 @@ final class CallResponse { final int mainLength = this.header.getSidecarOffsetsCount() == 0 ? this.message.length() : this.header.getSidecarOffsets(0); if (mainLength < 0 || mainLength > this.message.length()) { - throw new IllegalStateException("Main protobuf message invalid. " - + "Length is " + mainLength + " while the size of the message " - + "excluding the header is " + this.message.length()); + throw new IllegalStateException("Main protobuf message invalid. " + + "Length is " + mainLength + " while the size of the message " + + "excluding the header is " + this.message.length()); } return subslice(this.message, 0, mainLength); } @@ -113,8 +116,8 @@ final class CallResponse { List<Integer> sidecarList = this.header.getSidecarOffsetsList(); if (sidecar < 0 || sidecar > sidecarList.size()) { - throw new IllegalArgumentException("Sidecar " + sidecar - + " not valid, response has " + sidecarList.size() + " sidecars"); + throw new IllegalArgumentException("Sidecar " + sidecar + + " not valid, response has " + sidecarList.size() + " sidecars"); } final int prevOffset = sidecarList.get(sidecar); @@ -123,9 +126,9 @@ final class CallResponse { final int length = nextOffset - prevOffset; if (prevOffset < 0 || length < 0 || prevOffset + length > this.message.length()) { - throw new IllegalStateException("Sidecar " + sidecar + " invalid " - + "(offset = " + prevOffset + ", length = " + length + "). The size " - + "of the message " + "excluding the header is " + this.message.length()); + throw new IllegalStateException("Sidecar " + sidecar + " invalid " + + "(offset = " + prevOffset + ", length = " + length + "). The size " + + "of the message " + "excluding the header is " + this.message.length()); } return subslice(this.message, prevOffset, length); @@ -133,7 +136,9 @@ final class CallResponse { // Reads the message after the header if not read yet private void cacheMessage() { - if (this.message != null) return; + if (this.message != null) { + return; + } final int length = Bytes.readVarInt32(buf); this.message = nextBytes(buf, length); } http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/ColumnRangePredicate.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/ColumnRangePredicate.java b/java/kudu-client/src/main/java/org/apache/kudu/client/ColumnRangePredicate.java index f67204e..5a2f9e8 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/ColumnRangePredicate.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/ColumnRangePredicate.java @@ -14,19 +14,21 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.ZeroCopyLiteralByteString; + import org.apache.kudu.ColumnSchema; import org.apache.kudu.Type; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.tserver.Tserver; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - /** * A range predicate on one of the columns in the underlying data. * Both boundaries are inclusive. @@ -71,18 +73,29 @@ public class ColumnRangePredicate { private static KuduPredicate toKuduPredicate(ColumnSchema column, KuduPredicate.ComparisonOp op, byte[] bound) { - if (bound == null) { return null; } + if (bound == null) { + return null; + } switch (column.getType().getDataType()) { - case BOOL: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getBoolean(bound)); - case INT8: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getByte(bound)); - case INT16: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getShort(bound)); - case INT32: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getInt(bound)); + case BOOL: + return KuduPredicate.newComparisonPredicate(column, op, Bytes.getBoolean(bound)); + case INT8: + return KuduPredicate.newComparisonPredicate(column, op, Bytes.getByte(bound)); + case INT16: + return KuduPredicate.newComparisonPredicate(column, op, Bytes.getShort(bound)); + case INT32: + return KuduPredicate.newComparisonPredicate(column, op, Bytes.getInt(bound)); case INT64: - case UNIXTIME_MICROS: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getLong(bound)); - case FLOAT: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getFloat(bound)); - case DOUBLE: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getDouble(bound)); - case STRING: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getString(bound)); - case BINARY: return KuduPredicate.newComparisonPredicate(column, op, bound); + case UNIXTIME_MICROS: + return KuduPredicate.newComparisonPredicate(column, op, Bytes.getLong(bound)); + case FLOAT: + return KuduPredicate.newComparisonPredicate(column, op, Bytes.getFloat(bound)); + case DOUBLE: + return KuduPredicate.newComparisonPredicate(column, op, Bytes.getDouble(bound)); + case STRING: + return KuduPredicate.newComparisonPredicate(column, op, Bytes.getString(bound)); + case BINARY: + return KuduPredicate.newComparisonPredicate(column, op, bound); default: throw new IllegalStateException(String.format("unknown column type %s", column.getType())); } @@ -372,14 +385,16 @@ public class ColumnRangePredicate { } catch (InvalidProtocolBufferException e) { // We shade our pb dependency so we can't send out the exception above since other modules // won't know what to expect. - throw new IllegalArgumentException("Encountered an invalid column range predicate list: " - + Bytes.pretty(listBytes), e); + throw new IllegalArgumentException("Encountered an invalid column range predicate list: " + + Bytes.pretty(listBytes), e); } } private void checkColumn(Type... passedTypes) { for (Type type : passedTypes) { - if (this.column.getType().equals(type)) return; + if (this.column.getType().equals(type)) { + return; + } } throw new IllegalArgumentException(String.format("%s's type isn't %s, it's %s", column.getName(), Arrays.toString(passedTypes), column.getType().getName())); http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectionCache.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectionCache.java b/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectionCache.java index 9d8f1d0..c19dcae 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectionCache.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectionCache.java @@ -14,24 +14,9 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package org.apache.kudu.client; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; -import com.stumbleupon.async.Deferred; -import org.apache.kudu.Common; -import org.apache.kudu.annotations.InterfaceAudience; -import org.apache.kudu.annotations.InterfaceStability; -import org.apache.kudu.master.Master; -import org.apache.kudu.util.NetUtil; -import org.jboss.netty.channel.DefaultChannelPipeline; -import org.jboss.netty.channel.socket.SocketChannel; -import org.jboss.netty.channel.socket.SocketChannelConfig; -import org.jboss.netty.handler.timeout.ReadTimeoutHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +package org.apache.kudu.client; -import javax.annotation.concurrent.GuardedBy; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; @@ -42,6 +27,23 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import javax.annotation.concurrent.GuardedBy; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableList; +import com.stumbleupon.async.Deferred; +import org.jboss.netty.channel.DefaultChannelPipeline; +import org.jboss.netty.channel.socket.SocketChannel; +import org.jboss.netty.channel.socket.SocketChannelConfig; +import org.jboss.netty.handler.timeout.ReadTimeoutHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.kudu.Common; +import org.apache.kudu.annotations.InterfaceAudience; +import org.apache.kudu.annotations.InterfaceStability; +import org.apache.kudu.master.Master; +import org.apache.kudu.util.NetUtil; /** * The ConnectionCache is responsible for managing connections to masters and tablet servers. http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java b/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java index b4bf8b2..cfa4dca 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java @@ -14,13 +14,14 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import java.util.List; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import java.util.List; - import org.apache.kudu.Common; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.annotations.InterfaceStability; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableRequest.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableRequest.java b/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableRequest.java index 59aefa7..05f5c77 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableRequest.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableRequest.java @@ -14,18 +14,19 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package org.apache.kudu.client; -import com.google.protobuf.Message; +package org.apache.kudu.client; import java.util.Collection; import java.util.List; +import com.google.protobuf.Message; +import org.jboss.netty.buffer.ChannelBuffer; + import org.apache.kudu.Schema; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.master.Master; import org.apache.kudu.util.Pair; -import org.jboss.netty.buffer.ChannelBuffer; /** * RPC to create new tables @@ -58,7 +59,9 @@ class CreateTableRequest extends KuduRpc<CreateTableResponse> { } @Override - String serviceName() { return MASTER_SERVICE_NAME; } + String serviceName() { + return MASTER_SERVICE_NAME; + } @Override String method() { http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableResponse.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableResponse.java b/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableResponse.java index 7fa75b2..b579721 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableResponse.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableResponse.java @@ -14,10 +14,10 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import org.apache.kudu.annotations.InterfaceAudience; -import org.apache.kudu.annotations.InterfaceStability; @InterfaceAudience.Private public class CreateTableResponse extends KuduRpcResponse { http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/DeadlineTracker.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/DeadlineTracker.java b/java/kudu-client/src/main/java/org/apache/kudu/client/DeadlineTracker.java index d878d89..53f0098 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/DeadlineTracker.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/DeadlineTracker.java @@ -14,12 +14,13 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package org.apache.kudu.client; -import com.google.common.base.Stopwatch; +package org.apache.kudu.client; import java.util.concurrent.TimeUnit; +import com.google.common.base.Stopwatch; + /** * This is a wrapper class around {@link com.google.common.base.Stopwatch} used to track a relative * deadline in the future. http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/Delete.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/Delete.java b/java/kudu-client/src/main/java/org/apache/kudu/client/Delete.java index 295d093..4fe5bf9 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/Delete.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/Delete.java @@ -14,10 +14,9 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; -import org.apache.kudu.ColumnSchema; -import org.apache.kudu.Type; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.annotations.InterfaceStability; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableRequest.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableRequest.java b/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableRequest.java index dda31f6..83da304 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableRequest.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableRequest.java @@ -14,13 +14,15 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import com.google.protobuf.Message; +import org.jboss.netty.buffer.ChannelBuffer; + import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.master.Master; import org.apache.kudu.util.Pair; -import org.jboss.netty.buffer.ChannelBuffer; /** * RPC to delete tables @@ -42,13 +44,15 @@ class DeleteTableRequest extends KuduRpc<DeleteTableResponse> { assert header.isInitialized(); final Master.DeleteTableRequestPB.Builder builder = Master.DeleteTableRequestPB.newBuilder(); Master.TableIdentifierPB tableID = - Master.TableIdentifierPB.newBuilder().setTableName(name).build(); + Master.TableIdentifierPB.newBuilder().setTableName(name).build(); builder.setTable(tableID); return toChannelBuffer(header, builder.build()); } @Override - String serviceName() { return MASTER_SERVICE_NAME; } + String serviceName() { + return MASTER_SERVICE_NAME; + } @Override String method() { http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableResponse.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableResponse.java b/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableResponse.java index 9a75769..957b3ea 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableResponse.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/DeleteTableResponse.java @@ -14,6 +14,7 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import org.apache.kudu.annotations.InterfaceAudience; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/ErrorCollector.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/ErrorCollector.java b/java/kudu-client/src/main/java/org/apache/kudu/client/ErrorCollector.java index dda012b..a81bc0b 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/ErrorCollector.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/ErrorCollector.java @@ -14,15 +14,17 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import java.util.ArrayDeque; +import java.util.Queue; + import com.google.common.base.Preconditions; + import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.annotations.InterfaceStability; -import java.util.ArrayDeque; -import java.util.Queue; - /** * Class that helps tracking row errors. All methods are thread-safe. */ http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/ExternalConsistencyMode.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/ExternalConsistencyMode.java b/java/kudu-client/src/main/java/org/apache/kudu/client/ExternalConsistencyMode.java index 9f08a50..a37595b 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/ExternalConsistencyMode.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/ExternalConsistencyMode.java @@ -14,6 +14,7 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import org.apache.kudu.Common; @@ -35,6 +36,7 @@ public enum ExternalConsistencyMode { private ExternalConsistencyMode(Common.ExternalConsistencyMode pbVersion) { this.pbVersion = pbVersion; } + @InterfaceAudience.Private public Common.ExternalConsistencyMode pbVersion() { return pbVersion; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java b/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java index 02410a8..9bd71fc 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java @@ -14,8 +14,15 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + import com.google.common.base.Functions; import com.google.common.base.Joiner; import com.google.common.collect.Lists; @@ -23,19 +30,14 @@ import com.google.common.net.HostAndPort; import com.google.protobuf.ByteString; import com.stumbleupon.async.Callback; import com.stumbleupon.async.Deferred; -import org.apache.kudu.annotations.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.kudu.Common; +import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.consensus.Metadata; import org.apache.kudu.master.Master; import org.apache.kudu.util.NetUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; /** * Class grouping the callback and the errback for GetMasterRegistration calls http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationRequest.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationRequest.java b/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationRequest.java index c28e792..b0df178 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationRequest.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationRequest.java @@ -14,15 +14,19 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import static org.apache.kudu.consensus.Metadata.RaftPeerPB; +import static org.apache.kudu.master.Master.GetMasterRegistrationRequestPB; +import static org.apache.kudu.master.Master.GetMasterRegistrationResponsePB; +import static org.apache.kudu.master.Master.MasterErrorPB; + import com.google.protobuf.Message; -import static org.apache.kudu.consensus.Metadata.*; -import static org.apache.kudu.master.Master.*; +import org.jboss.netty.buffer.ChannelBuffer; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.util.Pair; -import org.jboss.netty.buffer.ChannelBuffer; /** * Package-private RPC that can only go to master. @@ -44,7 +48,9 @@ public class GetMasterRegistrationRequest extends KuduRpc<GetMasterRegistrationR } @Override - String serviceName() { return MASTER_SERVICE_NAME; } + String serviceName() { + return MASTER_SERVICE_NAME; + } @Override String method() { http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationResponse.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationResponse.java b/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationResponse.java index 559861f..7fa9f0c 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationResponse.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationResponse.java @@ -14,6 +14,7 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import org.apache.kudu.WireProtocol; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableLocationsRequest.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableLocationsRequest.java b/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableLocationsRequest.java index b535d6d..75857fa 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableLocationsRequest.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableLocationsRequest.java @@ -14,15 +14,17 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import com.google.protobuf.ByteString; import com.google.protobuf.Message; import com.google.protobuf.ZeroCopyLiteralByteString; +import org.jboss.netty.buffer.ChannelBuffer; + import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.master.Master; import org.apache.kudu.util.Pair; -import org.jboss.netty.buffer.ChannelBuffer; /** * Package-private RPC that can only go to a master. @@ -37,8 +39,8 @@ class GetTableLocationsRequest extends KuduRpc<Master.GetTableLocationsResponseP GetTableLocationsRequest(KuduTable table, byte[] startPartitionKey, byte[] endPartitionKey, String tableId) { super(table); - if (startPartitionKey != null && endPartitionKey != null - && Bytes.memcmp(startPartitionKey, endPartitionKey) > 0) { + if (startPartitionKey != null && endPartitionKey != null && + Bytes.memcmp(startPartitionKey, endPartitionKey) > 0) { throw new IllegalArgumentException( "The start partition key must be smaller or equal to the end partition key"); } @@ -48,7 +50,9 @@ class GetTableLocationsRequest extends KuduRpc<Master.GetTableLocationsResponseP } @Override - String serviceName() { return MASTER_SERVICE_NAME; } + String serviceName() { + return MASTER_SERVICE_NAME; + } @Override String method() { @@ -71,8 +75,8 @@ class GetTableLocationsRequest extends KuduRpc<Master.GetTableLocationsResponseP ChannelBuffer serialize(Message header) { final Master.GetTableLocationsRequestPB.Builder builder = Master .GetTableLocationsRequestPB.newBuilder(); - builder.setTable(Master.TableIdentifierPB.newBuilder(). - setTableId(ByteString.copyFromUtf8(tableId))); + builder.setTable(Master.TableIdentifierPB.newBuilder() + .setTableId(ByteString.copyFromUtf8(tableId))); if (startPartitionKey != null) { builder.setPartitionKeyStart(ZeroCopyLiteralByteString.wrap(startPartitionKey)); } http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaRequest.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaRequest.java b/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaRequest.java index 11a8405..07e3061 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaRequest.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaRequest.java @@ -14,15 +14,19 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import static org.apache.kudu.master.Master.GetTableSchemaRequestPB; +import static org.apache.kudu.master.Master.GetTableSchemaResponsePB; +import static org.apache.kudu.master.Master.TableIdentifierPB; + import com.google.protobuf.Message; -import static org.apache.kudu.master.Master.*; +import org.jboss.netty.buffer.ChannelBuffer; import org.apache.kudu.Schema; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.util.Pair; -import org.jboss.netty.buffer.ChannelBuffer; /** * RPC to fetch a table's schema @@ -49,7 +53,9 @@ public class GetTableSchemaRequest extends KuduRpc<GetTableSchemaResponse> { } @Override - String serviceName() { return MASTER_SERVICE_NAME; } + String serviceName() { + return MASTER_SERVICE_NAME; + } @Override String method() { http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaResponse.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaResponse.java b/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaResponse.java index 7421970..dc76a4f 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaResponse.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/GetTableSchemaResponse.java @@ -14,6 +14,7 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import org.apache.kudu.Schema; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/HasFailedRpcException.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/HasFailedRpcException.java b/java/kudu-client/src/main/java/org/apache/kudu/client/HasFailedRpcException.java index fa78d0a..c11c8c7 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/HasFailedRpcException.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/HasFailedRpcException.java @@ -23,6 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + package org.apache.kudu.client; import org.apache.kudu.annotations.InterfaceAudience; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/IPCUtil.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/IPCUtil.java b/java/kudu-client/src/main/java/org/apache/kudu/client/IPCUtil.java index 9da17ed..1770f2b 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/IPCUtil.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/IPCUtil.java @@ -16,14 +16,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.kudu.client; +import java.io.IOException; +import java.io.OutputStream; + import com.google.protobuf.CodedOutputStream; import com.google.protobuf.Message; -import org.apache.kudu.annotations.InterfaceAudience; -import java.io.IOException; -import java.io.OutputStream; +import org.apache.kudu.annotations.InterfaceAudience; /** * Helper methods for RPCs. @@ -53,7 +55,9 @@ public class IPCUtil { // I confirmed toBytes does same as say DataOutputStream#writeInt. dos.write(toBytes(totalSize)); header.writeDelimitedTo(dos); - if (param != null) param.writeDelimitedTo(dos); + if (param != null) { + param.writeDelimitedTo(dos); + } dos.flush(); return totalSize; } @@ -64,7 +68,9 @@ public class IPCUtil { public static int getTotalSizeWhenWrittenDelimited(Message ... messages) { int totalSize = 0; for (Message m: messages) { - if (m == null) continue; + if (m == null) { + continue; + } totalSize += m.getSerializedSize(); totalSize += CodedOutputStream.computeRawVarint32Size(m.getSerializedSize()); } @@ -73,7 +79,7 @@ public class IPCUtil { public static byte[] toBytes(int val) { byte [] b = new byte[4]; - for(int i = 3; i > 0; i--) { + for (int i = 3; i > 0; i--) { b[i] = (byte) val; val >>>= 8; } http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/Insert.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/Insert.java b/java/kudu-client/src/main/java/org/apache/kudu/client/Insert.java index 36490ea..0512dab 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/Insert.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/Insert.java @@ -14,6 +14,7 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import org.apache.kudu.annotations.InterfaceAudience; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneRequest.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneRequest.java b/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneRequest.java index dd42fe0..4b205cd 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneRequest.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneRequest.java @@ -14,14 +14,18 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import static org.apache.kudu.master.Master.IsAlterTableDoneRequestPB; +import static org.apache.kudu.master.Master.IsAlterTableDoneResponsePB; +import static org.apache.kudu.master.Master.TableIdentifierPB; + import com.google.protobuf.Message; -import static org.apache.kudu.master.Master.*; +import org.jboss.netty.buffer.ChannelBuffer; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.util.Pair; -import org.jboss.netty.buffer.ChannelBuffer; /** * RPC used to check if an alter is running for the specified table @@ -49,7 +53,9 @@ class IsAlterTableDoneRequest extends KuduRpc<IsAlterTableDoneResponse> { } @Override - String serviceName() { return MASTER_SERVICE_NAME; } + String serviceName() { + return MASTER_SERVICE_NAME; + } @Override String method() { http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneResponse.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneResponse.java b/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneResponse.java index 4dcc424..ed35ba7 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneResponse.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/IsAlterTableDoneResponse.java @@ -14,6 +14,7 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import org.apache.kudu.annotations.InterfaceAudience; http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/IsCreateTableDoneRequest.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/IsCreateTableDoneRequest.java b/java/kudu-client/src/main/java/org/apache/kudu/client/IsCreateTableDoneRequest.java index bfd6db9..42866b7 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/IsCreateTableDoneRequest.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/IsCreateTableDoneRequest.java @@ -14,14 +14,16 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import com.google.protobuf.ByteString; import com.google.protobuf.Message; +import org.jboss.netty.buffer.ChannelBuffer; + import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.master.Master; import org.apache.kudu.util.Pair; -import org.jboss.netty.buffer.ChannelBuffer; /** * Package-private RPC that can only go to a master. @@ -37,7 +39,9 @@ class IsCreateTableDoneRequest extends KuduRpc<Master.IsCreateTableDoneResponseP } @Override - String serviceName() { return MASTER_SERVICE_NAME; } + String serviceName() { + return MASTER_SERVICE_NAME; + } @Override String method() { http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/KeyEncoder.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KeyEncoder.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KeyEncoder.java index 6305d0d..c898e5f 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/KeyEncoder.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KeyEncoder.java @@ -14,8 +14,16 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + import com.google.common.primitives.Ints; import com.google.common.primitives.UnsignedLongs; import com.sangupta.murmur.Murmur2; @@ -28,13 +36,6 @@ import org.apache.kudu.client.PartitionSchema.HashBucketSchema; import org.apache.kudu.util.ByteVec; import org.apache.kudu.util.Pair; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - /** * Utility class for encoding rows into primary and partition keys. */ @@ -102,7 +103,8 @@ class KeyEncoder { * @param rangeSchema the range partition schema * @return the encoded range partition key */ - public static byte[] encodeRangePartitionKey(PartialRow row, PartitionSchema.RangeSchema rangeSchema) { + public static byte[] encodeRangePartitionKey(PartialRow row, + PartitionSchema.RangeSchema rangeSchema) { ByteVec buf = ByteVec.create(); encodeColumns(row, rangeSchema.getColumns(), buf); return buf.toArray(); @@ -283,11 +285,19 @@ class KeyEncoder { private static void decodeColumn(ByteBuffer buf, PartialRow row, int idx, boolean isLast) { Schema schema = row.getSchema(); switch (schema.getColumnByIndex(idx).getType()) { - case INT8: row.addByte(idx, (byte) (buf.get() ^ Byte.MIN_VALUE)); break; - case INT16: row.addShort(idx, (short) (buf.getShort() ^ Short.MIN_VALUE)); break; - case INT32: row.addInt(idx, buf.getInt() ^ Integer.MIN_VALUE); break; + case INT8: + row.addByte(idx, (byte) (buf.get() ^ Byte.MIN_VALUE)); + break; + case INT16: + row.addShort(idx, (short) (buf.getShort() ^ Short.MIN_VALUE)); + break; + case INT32: + row.addInt(idx, buf.getInt() ^ Integer.MIN_VALUE); + break; case INT64: - case UNIXTIME_MICROS: row.addLong(idx, buf.getLong() ^ Long.MIN_VALUE); break; + case UNIXTIME_MICROS: + row.addLong(idx, buf.getLong() ^ Long.MIN_VALUE); + break; case BINARY: { byte[] binary = decodeBinaryColumn(buf, isLast); row.addBinary(idx, binary); http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java index f7c6d5b..067fcc4 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java @@ -14,19 +14,20 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; -import com.stumbleupon.async.Deferred; -import org.apache.kudu.Schema; -import org.apache.kudu.annotations.InterfaceAudience; -import org.apache.kudu.annotations.InterfaceStability; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executor; +import com.stumbleupon.async.Deferred; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Executor; +import org.apache.kudu.Schema; +import org.apache.kudu.annotations.InterfaceAudience; +import org.apache.kudu.annotations.InterfaceStability; /** * A synchronous and thread-safe client for Kudu. @@ -285,7 +286,7 @@ public class KuduClient implements AutoCloseable { */ @InterfaceAudience.Public @InterfaceStability.Evolving - public final static class KuduClientBuilder { + public static final class KuduClientBuilder { private AsyncKuduClient.AsyncKuduClientBuilder clientBuilder; /** http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/KuduException.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduException.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduException.java index 555cb22..21d47c3 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduException.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduException.java @@ -23,15 +23,17 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + package org.apache.kudu.client; +import java.io.IOException; + import com.stumbleupon.async.DeferredGroupException; import com.stumbleupon.async.TimeoutException; + import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.annotations.InterfaceStability; -import java.io.IOException; - /** * The parent class of all exceptions sent by the Kudu client. This is the only exception you will * see if you're using the non-async API, such as {@link KuduSession} instead of http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/KuduPredicate.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduPredicate.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduPredicate.java index a78d63d..eea1d8c 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduPredicate.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduPredicate.java @@ -17,6 +17,14 @@ package org.apache.kudu.client; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.base.Objects; @@ -31,14 +39,6 @@ import org.apache.kudu.Type; import org.apache.kudu.annotations.InterfaceAudience; import org.apache.kudu.annotations.InterfaceStability; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - /** * A predicate which can be used to filter rows based on the value of a column. */ @@ -198,15 +198,20 @@ public class KuduPredicate { bytes = Bytes.fromLong(value); break; } - default: throw new RuntimeException("already checked"); + default: + throw new RuntimeException("already checked"); } switch (op) { case GREATER: - case GREATER_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, bytes, null); - case EQUAL: return new KuduPredicate(PredicateType.EQUALITY, column, bytes, null); + case GREATER_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, bytes, null); + case EQUAL: + return new KuduPredicate(PredicateType.EQUALITY, column, bytes, null); case LESS: - case LESS_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, null, bytes); - default: throw new RuntimeException("unknown comparison op"); + case LESS_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, null, bytes); + default: + throw new RuntimeException("unknown comparison op"); } } @@ -235,11 +240,15 @@ public class KuduPredicate { byte[] bytes = Bytes.fromFloat(value); switch (op) { case GREATER: - case GREATER_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, bytes, null); - case EQUAL: return new KuduPredicate(PredicateType.EQUALITY, column, bytes, null); + case GREATER_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, bytes, null); + case EQUAL: + return new KuduPredicate(PredicateType.EQUALITY, column, bytes, null); case LESS: - case LESS_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, null, bytes); - default: throw new RuntimeException("unknown comparison op"); + case LESS_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, null, bytes); + default: + throw new RuntimeException("unknown comparison op"); } } @@ -268,11 +277,15 @@ public class KuduPredicate { byte[] bytes = Bytes.fromDouble(value); switch (op) { case GREATER: - case GREATER_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, bytes, null); - case EQUAL: return new KuduPredicate(PredicateType.EQUALITY, column, bytes, null); + case GREATER_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, bytes, null); + case EQUAL: + return new KuduPredicate(PredicateType.EQUALITY, column, bytes, null); case LESS: - case LESS_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, null, bytes); - default: throw new RuntimeException("unknown comparison op"); + case LESS_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, null, bytes); + default: + throw new RuntimeException("unknown comparison op"); } } @@ -294,11 +307,15 @@ public class KuduPredicate { switch (op) { case GREATER: - case GREATER_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, bytes, null); - case EQUAL: return new KuduPredicate(PredicateType.EQUALITY, column, bytes, null); + case GREATER_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, bytes, null); + case EQUAL: + return new KuduPredicate(PredicateType.EQUALITY, column, bytes, null); case LESS: - case LESS_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, null, bytes); - default: throw new RuntimeException("unknown comparison op"); + case LESS_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, null, bytes); + default: + throw new RuntimeException("unknown comparison op"); } } @@ -319,11 +336,15 @@ public class KuduPredicate { switch (op) { case GREATER: - case GREATER_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, value, null); - case EQUAL: return new KuduPredicate(PredicateType.EQUALITY, column, value, null); + case GREATER_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, value, null); + case EQUAL: + return new KuduPredicate(PredicateType.EQUALITY, column, value, null); case LESS: - case LESS_EQUAL: return new KuduPredicate(PredicateType.RANGE, column, null, value); - default: throw new RuntimeException("unknown comparison op"); + case LESS_EQUAL: + return new KuduPredicate(PredicateType.RANGE, column, null, value); + default: + throw new RuntimeException("unknown comparison op"); } } @@ -338,7 +359,9 @@ public class KuduPredicate { * @return an IN list predicate */ public static <T> KuduPredicate newInListPredicate(final ColumnSchema column, List<T> values) { - if (values.isEmpty()) return none(column); + if (values.isEmpty()) { + return none(column); + } T t = values.get(0); SortedSet<byte[]> vals = new TreeSet<>(new Comparator<byte[]>() { @@ -469,12 +492,16 @@ public class KuduPredicate { "predicates from different columns may not be merged"); // NONE predicates dominate. - if (other.type == PredicateType.NONE) return other; + if (other.type == PredicateType.NONE) { + return other; + } // NOT NULL is dominated by all other predicates. // Note: this will no longer be true when an IS NULL predicate type is // added. - if (other.type == PredicateType.IS_NOT_NULL) return this; + if (other.type == PredicateType.IS_NOT_NULL) { + return this; + } switch (type) { case NONE: return this; @@ -755,9 +782,13 @@ public class KuduPredicate { } case STRING: case BINARY: { - if (a.length + 1 != b.length || b[a.length] != 0) return false; + if (a.length + 1 != b.length || b[a.length] != 0) { + return false; + } for (int i = 0; i < a.length; i++) { - if (a[i] != b[i]) return false; + if (a[i] != b[i]) { + return false; + } } return true; } @@ -795,12 +826,17 @@ public class KuduPredicate { @VisibleForTesting static long maxIntValue(Type type) { switch (type) { - case INT8: return Byte.MAX_VALUE; - case INT16: return Short.MAX_VALUE; - case INT32: return Integer.MAX_VALUE; + case INT8: + return Byte.MAX_VALUE; + case INT16: + return Short.MAX_VALUE; + case INT32: + return Integer.MAX_VALUE; case UNIXTIME_MICROS: - case INT64: return Long.MAX_VALUE; - default: throw new IllegalArgumentException("type must be an integer type"); + case INT64: + return Long.MAX_VALUE; + default: + throw new IllegalArgumentException("type must be an integer type"); } } @@ -812,12 +848,17 @@ public class KuduPredicate { @VisibleForTesting static long minIntValue(Type type) { switch (type) { - case INT8: return Byte.MIN_VALUE; - case INT16: return Short.MIN_VALUE; - case INT32: return Integer.MIN_VALUE; + case INT8: + return Byte.MIN_VALUE; + case INT16: + return Short.MIN_VALUE; + case INT32: + return Integer.MIN_VALUE; case UNIXTIME_MICROS: - case INT64: return Long.MIN_VALUE; - default: throw new IllegalArgumentException("type must be an integer type"); + case INT64: + return Long.MIN_VALUE; + default: + throw new IllegalArgumentException("type must be an integer type"); } } @@ -828,7 +869,9 @@ public class KuduPredicate { */ private static void checkColumn(ColumnSchema column, Type... passedTypes) { for (Type type : passedTypes) { - if (column.getType().equals(type)) return; + if (column.getType().equals(type)) { + return; + } } throw new IllegalArgumentException(String.format("%s's type isn't %s, it's %s", column.getName(), Arrays.toString(passedTypes), @@ -894,8 +937,12 @@ public class KuduPredicate { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } KuduPredicate that = (KuduPredicate) o; return type == that.type && column.equals(that.column) && http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpc.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpc.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpc.java index 979dbcc..0bf5ea9 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpc.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpc.java @@ -23,8 +23,17 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + package org.apache.kudu.client; +import static org.apache.kudu.client.ExternalConsistencyMode.CLIENT_PROPAGATED; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.protobuf.CodedOutputStream; @@ -33,19 +42,12 @@ import com.google.protobuf.Message; import com.stumbleupon.async.Deferred; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; -import org.apache.kudu.annotations.InterfaceAudience; -import org.apache.kudu.util.Pair; -import org.apache.kudu.util.Slice; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import static org.apache.kudu.client.ExternalConsistencyMode.CLIENT_PROPAGATED; +import org.apache.kudu.annotations.InterfaceAudience; +import org.apache.kudu.util.Pair; +import org.apache.kudu.util.Slice; /** * Abstract base class for all RPC requests going out to Kudu. @@ -370,7 +372,7 @@ public abstract class KuduRpc<R> { static ChannelBuffer toChannelBuffer(Message header, Message pb) { int totalSize = IPCUtil.getTotalSizeWhenWrittenDelimited(header, pb); - byte[] buf = new byte[totalSize+4]; + byte[] buf = new byte[totalSize + 4]; ChannelBuffer chanBuf = ChannelBuffers.wrappedBuffer(buf); chanBuf.clear(); chanBuf.writeInt(totalSize); @@ -413,12 +415,12 @@ public abstract class KuduRpc<R> { // either too large, or is negative (if the most-significant bit is set). if ((length & MAX_BYTE_ARRAY_MASK) != 0) { if (length < 0) { - throw new IllegalArgumentException("Read negative byte array length: " - + length + " in buf=" + buf + '=' + Bytes.pretty(buf)); + throw new IllegalArgumentException("Read negative byte array length: " + + length + " in buf=" + buf + '=' + Bytes.pretty(buf)); } else { - throw new IllegalArgumentException("Read byte array length that's too" - + " large: " + length + " > " + ~MAX_BYTE_ARRAY_MASK + " in buf=" - + buf + '=' + Bytes.pretty(buf)); + throw new IllegalArgumentException("Read byte array length that's too" + + " large: " + length + " > " + ~MAX_BYTE_ARRAY_MASK + " in buf=" + + buf + '=' + Bytes.pretty(buf)); } } } http://git-wip-us.apache.org/repos/asf/kudu/blob/22067edb/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpcResponse.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpcResponse.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpcResponse.java index c13bb19..96ce830 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpcResponse.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduRpcResponse.java @@ -14,6 +14,7 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. + package org.apache.kudu.client; import org.apache.kudu.annotations.InterfaceAudience;
