HBASE-12288 Support DirectByteBuffer usage in DataBlock Encoding area.
This commit is contained in:
parent
dcc06d90ad
commit
f0cf56f6f7
@ -137,7 +137,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
protected void createKeyOnlyKeyValue(byte[] keyBuffer, long memTS) {
|
||||
protected void setKey(byte[] keyBuffer, long memTS) {
|
||||
currentKey.setKey(keyBuffer, 0, keyLength);
|
||||
memstoreTS = memTS;
|
||||
}
|
||||
@ -302,11 +302,8 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
KeyValue kv = KeyValueUtil.copyToNewKeyValue(this);
|
||||
if (kv == null) {
|
||||
return "null";
|
||||
}
|
||||
return kv.toString();
|
||||
return KeyValue.keyToString(this.keyBuffer, 0, KeyValueUtil.keyLength(this)) + "/vlen="
|
||||
+ getValueLength() + "/seqid=" + memstoreTS;
|
||||
}
|
||||
|
||||
public Cell shallowCopy() {
|
||||
@ -575,7 +572,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
current.tagCompressionContext = tagCompressionContext;
|
||||
}
|
||||
decodeFirst();
|
||||
current.createKeyOnlyKeyValue(current.keyBuffer, current.memstoreTS);
|
||||
current.setKey(current.keyBuffer, current.memstoreTS);
|
||||
previous.invalidate();
|
||||
}
|
||||
|
||||
@ -588,9 +585,10 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
|
||||
@Override
|
||||
public ByteBuffer getValueShallowCopy() {
|
||||
return ByteBuffer.wrap(currentBuffer.array(),
|
||||
currentBuffer.arrayOffset() + current.valueOffset,
|
||||
current.valueLength);
|
||||
ByteBuffer dup = currentBuffer.duplicate();
|
||||
dup.position(current.valueOffset);
|
||||
dup.limit(current.valueOffset + current.valueLength);
|
||||
return dup.slice();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -599,8 +597,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
kvBuffer.putInt(current.keyLength);
|
||||
kvBuffer.putInt(current.valueLength);
|
||||
kvBuffer.put(current.keyBuffer, 0, current.keyLength);
|
||||
kvBuffer.put(currentBuffer.array(),
|
||||
currentBuffer.arrayOffset() + current.valueOffset,
|
||||
ByteBufferUtils.copyFromBufferToBuffer(kvBuffer, currentBuffer, current.valueOffset,
|
||||
current.valueLength);
|
||||
if (current.tagsLength > 0) {
|
||||
// Put short as unsigned
|
||||
@ -609,7 +606,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
if (current.tagsOffset != -1) {
|
||||
// the offset of the tags bytes in the underlying buffer is marked. So the temp
|
||||
// buffer,tagsBuffer was not been used.
|
||||
kvBuffer.put(currentBuffer.array(), currentBuffer.arrayOffset() + current.tagsOffset,
|
||||
ByteBufferUtils.copyFromBufferToBuffer(kvBuffer, currentBuffer, current.tagsOffset,
|
||||
current.tagsLength);
|
||||
} else {
|
||||
// When tagsOffset is marked as -1, tag compression was present and so the tags were
|
||||
@ -639,7 +636,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
tagCompressionContext.clear();
|
||||
}
|
||||
decodeFirst();
|
||||
current.createKeyOnlyKeyValue(current.keyBuffer, current.memstoreTS);
|
||||
current.setKey(current.keyBuffer, current.memstoreTS);
|
||||
previous.invalidate();
|
||||
}
|
||||
|
||||
@ -649,7 +646,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
return false;
|
||||
}
|
||||
decodeNext();
|
||||
current.createKeyOnlyKeyValue(current.keyBuffer, current.memstoreTS);
|
||||
current.setKey(current.keyBuffer, current.memstoreTS);
|
||||
previous.invalidate();
|
||||
return true;
|
||||
}
|
||||
@ -672,7 +669,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
}
|
||||
current.tagsOffset = -1;
|
||||
} else {
|
||||
// When tag compress is not used, let us not do temp copying of tags bytes into tagsBuffer.
|
||||
// When tag compress is not used, let us not do copying of tags bytes into tagsBuffer.
|
||||
// Just mark the tags Offset so as to create the KV buffer later in getKeyValueBuffer()
|
||||
current.tagsOffset = currentBuffer.position();
|
||||
ByteBufferUtils.skip(currentBuffer, current.tagsLength);
|
||||
@ -783,7 +780,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
|
||||
if (currentBuffer.hasRemaining()) {
|
||||
previous.copyFromNext(current);
|
||||
decodeNext();
|
||||
current.createKeyOnlyKeyValue(current.keyBuffer, current.memstoreTS);
|
||||
current.setKey(current.keyBuffer, current.memstoreTS);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -68,11 +68,13 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder {
|
||||
@Override
|
||||
public ByteBuffer getFirstKeyInBlock(ByteBuffer block) {
|
||||
int keyLength = block.getInt(Bytes.SIZEOF_INT);
|
||||
return ByteBuffer.wrap(block.array(),
|
||||
block.arrayOffset() + 3 * Bytes.SIZEOF_INT, keyLength).slice();
|
||||
ByteBuffer dup = block.duplicate();
|
||||
int pos = 3 * Bytes.SIZEOF_INT;
|
||||
dup.position(pos);
|
||||
dup.limit(pos + keyLength);
|
||||
return dup.slice();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CopyKeyDataBlockEncoder.class.getSimpleName();
|
||||
@ -123,5 +125,4 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder {
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -317,6 +317,7 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
|
||||
ByteBuffer result = ByteBuffer.allocate(keyLength);
|
||||
|
||||
// copy row
|
||||
assert !(result.isDirect());
|
||||
int pos = result.arrayOffset();
|
||||
block.get(result.array(), pos, Bytes.SIZEOF_SHORT);
|
||||
pos += Bytes.SIZEOF_SHORT;
|
||||
|
@ -362,8 +362,10 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
|
||||
ByteBufferUtils.readCompressedInt(block); // commonLength
|
||||
int pos = block.position();
|
||||
block.reset();
|
||||
return ByteBuffer.wrap(block.array(), block.arrayOffset() + pos, keyLength)
|
||||
.slice();
|
||||
ByteBuffer dup = block.duplicate();
|
||||
dup.position(pos);
|
||||
dup.limit(pos + keyLength);
|
||||
return dup.slice();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -184,8 +184,10 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
|
||||
}
|
||||
int pos = block.position();
|
||||
block.reset();
|
||||
return ByteBuffer.wrap(block.array(), block.arrayOffset() + pos, keyLength)
|
||||
.slice();
|
||||
ByteBuffer dup = block.duplicate();
|
||||
dup.position(pos);
|
||||
dup.limit(pos + keyLength);
|
||||
return dup.slice();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -331,7 +331,10 @@ public final class ByteBufferUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy from one buffer to another from given offset
|
||||
* Copy from one buffer to another from given offset.
|
||||
* <p>
|
||||
* Note : This will advance the position marker of {@code out} but not change the position maker
|
||||
* for {@code in}
|
||||
* @param out destination buffer
|
||||
* @param in source buffer
|
||||
* @param sourceOffset offset in the source buffer
|
||||
|
Loading…
x
Reference in New Issue
Block a user