HBASE-25387 TagRewriteCell's getSerializedSize() method gets the size wrong
This commit is contained in:
parent
86bb037eb0
commit
1c2fcb20c6
|
@ -275,7 +275,7 @@ public final class PrivateCellUtil {
|
||||||
@Override
|
@Override
|
||||||
public int write(OutputStream out, boolean withTags) throws IOException {
|
public int write(OutputStream out, boolean withTags) throws IOException {
|
||||||
int len = ((ExtendedCell) this.cell).write(out, false);
|
int len = ((ExtendedCell) this.cell).write(out, false);
|
||||||
if (withTags && this.tags != null) {
|
if (withTags && this.tags != null && this.tags.length > 0) {
|
||||||
// Write the tagsLength 2 bytes
|
// Write the tagsLength 2 bytes
|
||||||
out.write((byte) (0xff & (this.tags.length >> 8)));
|
out.write((byte) (0xff & (this.tags.length >> 8)));
|
||||||
out.write((byte) (0xff & this.tags.length));
|
out.write((byte) (0xff & this.tags.length));
|
||||||
|
@ -288,7 +288,7 @@ public final class PrivateCellUtil {
|
||||||
@Override
|
@Override
|
||||||
public int getSerializedSize(boolean withTags) {
|
public int getSerializedSize(boolean withTags) {
|
||||||
int len = ((ExtendedCell) this.cell).getSerializedSize(false);
|
int len = ((ExtendedCell) this.cell).getSerializedSize(false);
|
||||||
if (withTags && this.tags != null) {
|
if (withTags && this.tags != null && this.tags.length > 0) {
|
||||||
len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length;
|
len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
|
@ -454,7 +454,7 @@ public final class PrivateCellUtil {
|
||||||
@Override
|
@Override
|
||||||
public int write(OutputStream out, boolean withTags) throws IOException {
|
public int write(OutputStream out, boolean withTags) throws IOException {
|
||||||
int len = ((ExtendedCell) this.cell).write(out, false);
|
int len = ((ExtendedCell) this.cell).write(out, false);
|
||||||
if (withTags && this.tags != null) {
|
if (withTags && this.tags != null && this.tags.length > 0) {
|
||||||
// Write the tagsLength 2 bytes
|
// Write the tagsLength 2 bytes
|
||||||
out.write((byte) (0xff & (this.tags.length >> 8)));
|
out.write((byte) (0xff & (this.tags.length >> 8)));
|
||||||
out.write((byte) (0xff & this.tags.length));
|
out.write((byte) (0xff & this.tags.length));
|
||||||
|
@ -467,7 +467,7 @@ public final class PrivateCellUtil {
|
||||||
@Override
|
@Override
|
||||||
public int getSerializedSize(boolean withTags) {
|
public int getSerializedSize(boolean withTags) {
|
||||||
int len = ((ExtendedCell) this.cell).getSerializedSize(false);
|
int len = ((ExtendedCell) this.cell).getSerializedSize(false);
|
||||||
if (withTags && this.tags != null) {
|
if (withTags && this.tags != null && this.tags.length > 0) {
|
||||||
len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length;
|
len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
|
@ -597,7 +597,7 @@ public final class PrivateCellUtil {
|
||||||
out.write(value);// Value
|
out.write(value);// Value
|
||||||
}
|
}
|
||||||
len += valLen;
|
len += valLen;
|
||||||
if (withTags && tags != null) {
|
if (withTags && tags != null && tags.length > 0) {
|
||||||
// Write the tagsLength 2 bytes
|
// Write the tagsLength 2 bytes
|
||||||
out.write((byte) (0xff & (tags.length >> 8)));
|
out.write((byte) (0xff & (tags.length >> 8)));
|
||||||
out.write((byte) (0xff & tags.length));
|
out.write((byte) (0xff & tags.length));
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase;
|
package org.apache.hadoop.hbase;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.io.HeapSize;
|
import org.apache.hadoop.hbase.io.HeapSize;
|
||||||
|
@ -25,6 +26,7 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
@Category(SmallTests.class)
|
@Category(SmallTests.class)
|
||||||
public class TestTagRewriteCell {
|
public class TestTagRewriteCell {
|
||||||
|
@ -33,6 +35,23 @@ public class TestTagRewriteCell {
|
||||||
public static final HBaseClassTestRule CLASS_RULE =
|
public static final HBaseClassTestRule CLASS_RULE =
|
||||||
HBaseClassTestRule.forClass(TestTagRewriteCell.class);
|
HBaseClassTestRule.forClass(TestTagRewriteCell.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializedSize(){
|
||||||
|
Cell originalCell = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
|
||||||
|
.setRow(Bytes.toBytes("row"))
|
||||||
|
.setFamily(Bytes.toBytes("family"))
|
||||||
|
.setQualifier(Bytes.toBytes("qualifier"))
|
||||||
|
.setTimestamp(HConstants.LATEST_TIMESTAMP)
|
||||||
|
.setType(KeyValue.Type.Maximum.getCode())
|
||||||
|
.setValue(Bytes.toBytes("value"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ByteBuffer byteBuffer = ByteBuffer.allocate(100);
|
||||||
|
Cell cell = PrivateCellUtil.createCell(originalCell, "".getBytes());
|
||||||
|
int lengthWriten = KeyValueUtil.appendTo(cell, byteBuffer, 0, true);
|
||||||
|
assertEquals(cell.getSerializedSize(), lengthWriten);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeapSize() {
|
public void testHeapSize() {
|
||||||
Cell originalCell = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
|
Cell originalCell = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
|
||||||
|
|
Loading…
Reference in New Issue