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:45:10 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 e65f43000 -> 4d8bcd462


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>

Conflicts:
	hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java


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

Branch: refs/heads/branch-1
Commit: 4d8bcd46298f6e613e37757e5eb141d5c6192a07
Parents: e65f430
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:41:39 2015 -0500

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/util/Bytes.java     | 16 ++++++++++++--
 .../org/apache/hadoop/hbase/util/TestBytes.java | 14 +++++++++++++
 .../hadoop/hbase/io/hfile/HFileReaderV2.java    | 22 +++++++-------------
 .../hadoop/hbase/io/hfile/HFileReaderV3.java    | 10 +++------
 4 files changed, 38 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/4d8bcd46/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 dd666e6..e7c9522 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
@@ -1156,14 +1156,26 @@ public class 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/4d8bcd46/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 1a76536..5c798ac 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
@@ -30,6 +30,7 @@ import java.util.Random;
 import junit.framework.TestCase;
 
 import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.io.WritableUtils;
 import org.junit.Assert;
 import org.junit.experimental.categories.Category;
 
@@ -212,6 +213,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/4d8bcd46/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
index c0e3e91..833f851 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
@@ -938,13 +938,9 @@ public class HFileReaderV2 extends AbstractHFileReader {
     protected void readMvccVersion() {
       if (this.reader.shouldIncludeMemstoreTS()) {
         if (this.reader.decodeMemstoreTS) {
-          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;
@@ -982,14 +978,10 @@ public class HFileReaderV2 extends AbstractHFileReader {
         blockBuffer.reset();
         if (this.reader.shouldIncludeMemstoreTS()) {
           if (this.reader.decodeMemstoreTS) {
-            try {
-              int memstoreTSOffset = blockBuffer.arrayOffset() + blockBuffer.position()
-                  + KEY_VALUE_LEN_SIZE + klen + vlen;
-              memstoreTS = Bytes.readVLong(blockBuffer.array(), memstoreTSOffset);
-              memstoreTSLen = WritableUtils.getVIntSize(memstoreTS);
-            } catch (Exception e) {
-              throw new RuntimeException("Error reading memstore timestamp", e);
-            }
+            int memstoreTSOffset = blockBuffer.arrayOffset() + blockBuffer.position()
+                + KEY_VALUE_LEN_SIZE + klen + vlen;
+            memstoreTS = Bytes.readAsVLong(blockBuffer.array(), memstoreTSOffset);
+            memstoreTSLen = WritableUtils.getVIntSize(memstoreTS);
           } else {
             memstoreTS = 0;
             memstoreTSLen = 1;

http://git-wip-us.apache.org/repos/asf/hbase/blob/4d8bcd46/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV3.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV3.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV3.java
index b28d8c1..13a8aef 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV3.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV3.java
@@ -275,13 +275,9 @@ public class HFileReaderV3 extends HFileReaderV2 {
         }
         if (this.reader.shouldIncludeMemstoreTS()) {
           if (this.reader.decodeMemstoreTS) {
-            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;


Mime
View raw message