HBASE-26856:BufferedDataBlockEncoder.OnheapDecodedCell value can get corrupted (#4394)
Created OnheapDecodedCell and OffheapDecodedExtendedCell objects with duplicate copy of ByteBuffer's underlying array instead of original ByteBuffer
Signed-off-by: Andrew Purtell <apurtell@apache.org>
Signed-off-by: Pankaj Kumar<pankajkumar@apache.org>
(cherry picked from commit c198f23e5e
)
This commit is contained in:
parent
31f4b422ab
commit
de9a17e75c
|
@ -232,9 +232,10 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder {
|
||||||
int tOffset = 0;
|
int tOffset = 0;
|
||||||
if (this.includeTags) {
|
if (this.includeTags) {
|
||||||
if (this.tagCompressionContext == null) {
|
if (this.tagCompressionContext == null) {
|
||||||
tagsArray = valAndTagsBuffer.array();
|
|
||||||
tOffset =
|
tOffset =
|
||||||
valAndTagsBuffer.arrayOffset() + vOffset + this.valueLength + tagsLenSerializationSize;
|
valAndTagsBuffer.arrayOffset() + vOffset + this.valueLength + tagsLenSerializationSize;
|
||||||
|
tagsArray = Bytes.copy(valAndTagsBuffer.array(), tOffset, this.tagsLength);
|
||||||
|
tOffset = 0;
|
||||||
} else {
|
} else {
|
||||||
tagsArray = Bytes.copy(tagsBuffer, 0, this.tagsLength);
|
tagsArray = Bytes.copy(tagsBuffer, 0, this.tagsLength);
|
||||||
tOffset = 0;
|
tOffset = 0;
|
||||||
|
@ -243,9 +244,8 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder {
|
||||||
return new OnheapDecodedCell(Bytes.copy(keyBuffer, 0, this.keyLength),
|
return new OnheapDecodedCell(Bytes.copy(keyBuffer, 0, this.keyLength),
|
||||||
currentKey.getRowLength(), currentKey.getFamilyOffset(), currentKey.getFamilyLength(),
|
currentKey.getRowLength(), currentKey.getFamilyOffset(), currentKey.getFamilyLength(),
|
||||||
currentKey.getQualifierOffset(), currentKey.getQualifierLength(), currentKey.getTimestamp(),
|
currentKey.getQualifierOffset(), currentKey.getQualifierLength(), currentKey.getTimestamp(),
|
||||||
currentKey.getTypeByte(), valAndTagsBuffer.array(),
|
currentKey.getTypeByte(), Bytes.copy(valAndTagsBuffer.array(), valAndTagsBuffer.arrayOffset() + vOffset,
|
||||||
valAndTagsBuffer.arrayOffset() + vOffset, this.valueLength, memstoreTS, tagsArray, tOffset,
|
this.valueLength), 0, this.valueLength, memstoreTS, tagsArray, tOffset, this.tagsLength);
|
||||||
this.tagsLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cell toOffheapCell(ByteBuffer valAndTagsBuffer, int vOffset,
|
private Cell toOffheapCell(ByteBuffer valAndTagsBuffer, int vOffset,
|
||||||
|
@ -254,13 +254,26 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder {
|
||||||
int tOffset = 0;
|
int tOffset = 0;
|
||||||
if (this.includeTags) {
|
if (this.includeTags) {
|
||||||
if (this.tagCompressionContext == null) {
|
if (this.tagCompressionContext == null) {
|
||||||
tagsBuf = valAndTagsBuffer;
|
|
||||||
tOffset = vOffset + this.valueLength + tagsLenSerializationSize;
|
tOffset = vOffset + this.valueLength + tagsLenSerializationSize;
|
||||||
|
byte[] output = new byte[this.tagsLength];
|
||||||
|
ByteBufferUtils.copyFromBufferToArray(output, valAndTagsBuffer, tOffset, 0,
|
||||||
|
this.tagsLength);
|
||||||
|
tagsBuf = ByteBuffer.wrap(output);
|
||||||
|
tOffset = 0;
|
||||||
} else {
|
} else {
|
||||||
tagsBuf = ByteBuffer.wrap(Bytes.copy(tagsBuffer, 0, this.tagsLength));
|
tagsBuf = ByteBuffer.wrap(Bytes.copy(tagsBuffer, 0, this.tagsLength));
|
||||||
tOffset = 0;
|
tOffset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.valueLength > 0) {
|
||||||
|
byte[] output = new byte[this.valueLength];
|
||||||
|
ByteBufferUtils.copyFromBufferToArray(output, valAndTagsBuffer, vOffset, 0,
|
||||||
|
this.valueLength);
|
||||||
|
valAndTagsBuffer = ByteBuffer.wrap(output);
|
||||||
|
vOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return new OffheapDecodedExtendedCell(
|
return new OffheapDecodedExtendedCell(
|
||||||
ByteBuffer.wrap(Bytes.copy(keyBuffer, 0, this.keyLength)), currentKey.getRowLength(),
|
ByteBuffer.wrap(Bytes.copy(keyBuffer, 0, this.keyLength)), currentKey.getRowLength(),
|
||||||
currentKey.getFamilyOffset(), currentKey.getFamilyLength(), currentKey.getQualifierOffset(),
|
currentKey.getFamilyOffset(), currentKey.getFamilyLength(), currentKey.getQualifierOffset(),
|
||||||
|
|
Loading…
Reference in New Issue