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..2bdbaed 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,12 +1364,28 @@ public class Bytes implements Comparable { } /** - * 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. + * @return deserialized long from stream. + */ + public static long readAsVLong(final byte [] buffer, final int offset) { + try { + return readVLong(buffer, offset); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * 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. + * @deprecated Use {@link #readAsVLong()} instead. */ + @Deprecated public static long readVLong(final byte [] buffer, final int offset) throws IOException { byte firstByte = buffer[offset]; 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; 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;