Index: hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java (revision 1375311) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java (working copy) @@ -606,7 +606,9 @@ return null; KeyValue ret = new KeyValue(blockBuffer.array(), - blockBuffer.arrayOffset() + blockBuffer.position()); + blockBuffer.arrayOffset() + blockBuffer.position(), + KEY_VALUE_LEN_SIZE + currKeyLen + currValueLen, + currKeyLen); if (this.reader.shouldIncludeMemstoreTS()) { ret.setMemstoreTS(currMemstoreTS); } Index: hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java =================================================================== --- hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java (revision 1375311) +++ hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java (working copy) @@ -316,6 +316,22 @@ this.length = length; } + /** + * Creates a KeyValue from the specified byte array, starting at offset, + * for length length, and a know keyLength. + * Use with caution. + * @param bytes byte array + * @param offset offset to start of the KeyValue + * @param length length of the KeyValue + * @param keyLength length of the key portion of the KeyValue + */ + public KeyValue(final byte [] bytes, final int offset, final int length, final int keyLength) { + this.bytes = bytes; + this.offset = offset; + this.length = length; + this.keyLength = keyLength; + } + /** Constructors that build a new backing byte array from fields */ /** @@ -1279,22 +1295,18 @@ return Bytes.toLong(this.bytes, tsOffset); } + private byte type = -1; /** * @return Type of this KeyValue. */ public byte getType() { - return getType(getKeyLength()); + if (type == -1) { + type = this.bytes[this.offset + getKeyLength() - 1 + ROW_OFFSET]; + } + return type; } /** - * @param keylength Pass if you have it to save on a int creation. - * @return Type of this KeyValue. - */ - byte getType(final int keylength) { - return this.bytes[this.offset + keylength - 1 + ROW_OFFSET]; - } - - /** * @return True if a delete type, a {@link KeyValue.Type#Delete} or * a {KeyValue.Type#DeleteFamily} or a {@link KeyValue.Type#DeleteColumn} * KeyValue type. @@ -2560,7 +2572,7 @@ ClassSize.align(ClassSize.ARRAY) + ClassSize.align(length) + (3 * Bytes.SIZEOF_INT) + ClassSize.align(ClassSize.ARRAY) + - (2 * Bytes.SIZEOF_LONG)); + (2 * Bytes.SIZEOF_LONG) + Bytes.SIZEOF_BYTE); } // this overload assumes that the length bytes have already been read, @@ -2572,6 +2584,7 @@ this.offset = 0; this.timestampCache = -1; this.keyLength = 0; + this.type = -1; this.bytes = new byte[this.length]; in.readFully(this.bytes, 0, this.length); }