hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject hbase git commit: HBASE-6919 Remove unnecessary throws IOException from Bytes.readVLong.
Date Sat, 04 Apr 2015 02:36:40 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 6c2233359 -> e252c3064


HBASE-6919 Remove unnecessary throws IOException from Bytes.readVLong.

Added readAsVLong() to deprecate readVLong() which was throwing IOException. Added test for
readAsVLong().

Signed-off-by: Sean Busbey <busbey@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/e252c306
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e252c306
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e252c306

Branch: refs/heads/master
Commit: e252c30645d416697bbb22f1ca20846b3256a92a
Parents: 6c22333
Author: Apekshit(Appy) Sharma <appy@cloudera.com>
Authored: Fri Apr 3 17:23:27 2015 -0700
Committer: Sean Busbey <busbey@apache.org>
Committed: Fri Apr 3 21:25:37 2015 -0500

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/util/Bytes.java     | 16 ++++++++++++++--
 .../org/apache/hadoop/hbase/util/TestBytes.java | 14 ++++++++++++++
 .../hadoop/hbase/io/hfile/HFileReaderImpl.java  | 20 ++++++--------------
 3 files changed, 34 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/e252c306/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
index bec35ee..8096178 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
@@ -1364,14 +1364,26 @@ public class Bytes implements Comparable<Bytes> {
   }
 
   /**
-   * Reads a zero-compressed encoded long from input stream and returns it.
+   * Reads a zero-compressed encoded long from input buffer and returns it.
    * @param buffer Binary array
    * @param offset Offset into array at which vint begins.
    * @throws java.io.IOException e
-   * @return deserialized long from stream.
+   * @return deserialized long from buffer.
+   * @deprecated Use {@link #readAsVLong()} instead.
    */
+  @Deprecated
   public static long readVLong(final byte [] buffer, final int offset)
   throws IOException {
+    return readAsVLong(buffer, offset);
+  }
+
+  /**
+   * Reads a zero-compressed encoded long from input buffer and returns it.
+   * @param buffer Binary array
+   * @param offset Offset into array at which vint begins.
+   * @return deserialized long from buffer.
+   */
+  public static long readAsVLong(final byte [] buffer, final int offset) {
     byte firstByte = buffer[offset];
     int len = WritableUtils.decodeVIntSize(firstByte);
     if (len == 1) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/e252c306/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
index d948a2b..eb5e453 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
@@ -31,6 +31,7 @@ import junit.framework.TestCase;
 
 import org.apache.hadoop.hbase.testclassification.MiscTests;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.io.WritableUtils;
 import org.junit.Assert;
 import org.junit.experimental.categories.Category;
 
@@ -213,6 +214,19 @@ public class TestBytes extends TestCase {
     assertEquals(7, target.limit());
   }
 
+  public void testReadAsVLong() throws Exception {
+    long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE};
+    for (int i = 0; i < longs.length; i++) {
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      DataOutputStream output = new DataOutputStream(baos);
+      WritableUtils.writeVLong(output, longs[i]);
+      byte[] long_bytes_no_offset = baos.toByteArray();
+      assertEquals(longs[i], Bytes.readAsVLong(long_bytes_no_offset, 0));
+      byte[] long_bytes_with_offset = bytesWithOffset(long_bytes_no_offset);
+      assertEquals(longs[i], Bytes.readAsVLong(long_bytes_with_offset, 1));
+    }
+  }
+
   public void testToStringBinaryForBytes() {
     byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 };
     String actual = Bytes.toStringBinary(array);

http://git-wip-us.apache.org/repos/asf/hbase/blob/e252c306/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java
index a007f37..933ad22 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java
@@ -585,13 +585,9 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
         }
         if (this.reader.shouldIncludeMemstoreTS()) {
           if (this.reader.isDecodeMemstoreTS()) {
-            try {
-              memstoreTS = Bytes.readVLong(blockBuffer.array(), blockBuffer.arrayOffset()
-                  + blockBuffer.position());
-              memstoreTSLen = WritableUtils.getVIntSize(memstoreTS);
-            } catch (Exception e) {
-              throw new RuntimeException("Error reading memstore timestamp", e);
-            }
+            memstoreTS = Bytes.readAsVLong(blockBuffer.array(), blockBuffer.arrayOffset()
+                + blockBuffer.position());
+            memstoreTSLen = WritableUtils.getVIntSize(memstoreTS);
           } else {
             memstoreTS = 0;
             memstoreTSLen = 1;
@@ -973,13 +969,9 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
     protected void readMvccVersion() {
       if (this.reader.shouldIncludeMemstoreTS()) {
         if (this.reader.isDecodeMemstoreTS()) {
-          try {
-            currMemstoreTS = Bytes.readVLong(blockBuffer.array(), blockBuffer.arrayOffset()
-                + blockBuffer.position());
-            currMemstoreTSLen = WritableUtils.getVIntSize(currMemstoreTS);
-          } catch (Exception e) {
-            throw new RuntimeException("Error reading memstore timestamp", e);
-          }
+          currMemstoreTS = Bytes.readAsVLong(blockBuffer.array(), blockBuffer.arrayOffset()
+              + blockBuffer.position());
+          currMemstoreTSLen = WritableUtils.getVIntSize(currMemstoreTS);
         } else {
           currMemstoreTS = 0;
           currMemstoreTSLen = 1;


Mime
View raw message