HBASE-9956 Remove keyLength cache from KeyValue

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1541312 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2013-11-12 23:30:20 +00:00
parent 4837c424f3
commit 1427e3a431
3 changed files with 8 additions and 27 deletions

View File

@ -332,21 +332,6 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
this.length = length; this.length = length;
} }
/**
* Creates a KeyValue from the specified byte array, starting at offset,
* for length <code>length</code>, and a known <code>keyLength</code>.
* @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 */ /** Constructors that build a new backing byte array from fields */
/** /**
@ -1231,13 +1216,8 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
/** /**
* @return Length of key portion. * @return Length of key portion.
*/ */
private int keyLength = 0;
public int getKeyLength() { public int getKeyLength() {
if (keyLength == 0) { return Bytes.toInt(this.bytes, this.offset);
keyLength = Bytes.toInt(this.bytes, this.offset);
}
return keyLength;
} }
/** /**
@ -2856,7 +2836,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
sum += ClassSize.REFERENCE;// pointer to "bytes" sum += ClassSize.REFERENCE;// pointer to "bytes"
sum += ClassSize.align(ClassSize.ARRAY);// "bytes" sum += ClassSize.align(ClassSize.ARRAY);// "bytes"
sum += ClassSize.align(length);// number of bytes of data in the "bytes" array sum += ClassSize.align(length);// number of bytes of data in the "bytes" array
sum += 3 * Bytes.SIZEOF_INT;// offset, length, keyLength sum += 2 * Bytes.SIZEOF_INT;// offset, length
sum += Bytes.SIZEOF_LONG;// memstoreTS sum += Bytes.SIZEOF_LONG;// memstoreTS
return ClassSize.align(sum); return ClassSize.align(sum);
} }

View File

@ -651,7 +651,7 @@ public class HFileReaderV2 extends AbstractHFileReader {
return null; return null;
KeyValue ret = new KeyValue(blockBuffer.array(), blockBuffer.arrayOffset() KeyValue ret = new KeyValue(blockBuffer.array(), blockBuffer.arrayOffset()
+ blockBuffer.position(), getCellBufSize(), currKeyLen); + blockBuffer.position(), getCellBufSize());
if (this.reader.shouldIncludeMemstoreTS()) { if (this.reader.shouldIncludeMemstoreTS()) {
ret.setMvccVersion(currMemstoreTS); ret.setMvccVersion(currMemstoreTS);
} }

View File

@ -247,11 +247,12 @@ public class ScanQueryMatcher {
byte [] bytes = kv.getBuffer(); byte [] bytes = kv.getBuffer();
int offset = kv.getOffset(); int offset = kv.getOffset();
int initialOffset = offset;
int keyLength = Bytes.toInt(bytes, offset, Bytes.SIZEOF_INT); int keyLength = Bytes.toInt(bytes, offset, Bytes.SIZEOF_INT);
offset += KeyValue.ROW_OFFSET; offset += KeyValue.ROW_OFFSET;
int initialOffset = offset;
short rowLength = Bytes.toShort(bytes, offset, Bytes.SIZEOF_SHORT); short rowLength = Bytes.toShort(bytes, offset, Bytes.SIZEOF_SHORT);
offset += Bytes.SIZEOF_SHORT; offset += Bytes.SIZEOF_SHORT;
@ -282,10 +283,10 @@ public class ScanQueryMatcher {
byte familyLength = bytes [offset]; byte familyLength = bytes [offset];
offset += familyLength + 1; offset += familyLength + 1;
int qualLength = keyLength + KeyValue.ROW_OFFSET - int qualLength = keyLength -
(offset - initialOffset) - KeyValue.TIMESTAMP_TYPE_SIZE; (offset - initialOffset) - KeyValue.TIMESTAMP_TYPE_SIZE;
long timestamp = kv.getTimestamp(); long timestamp = Bytes.toLong(bytes, initialOffset + keyLength - KeyValue.TIMESTAMP_TYPE_SIZE);
// check for early out based on timestamp alone // check for early out based on timestamp alone
if (columns.isDone(timestamp)) { if (columns.isDone(timestamp)) {
return columns.getNextRowOrNextColumn(bytes, offset, qualLength); return columns.getNextRowOrNextColumn(bytes, offset, qualLength);
@ -304,7 +305,7 @@ public class ScanQueryMatcher {
* 7. Delete marker need to be version counted together with puts * 7. Delete marker need to be version counted together with puts
* they affect * they affect
*/ */
byte type = kv.getTypeByte(); byte type = bytes[initialOffset + keyLength - 1];
if (kv.isDelete()) { if (kv.isDelete()) {
if (!keepDeletedCells) { if (!keepDeletedCells) {
// first ignore delete markers if the scanner can do so, and the // first ignore delete markers if the scanner can do so, and the