From a7658591315a9adcb3c959dfdf5e35de526d99e6 Mon Sep 17 00:00:00 2001 From: huzheng Date: Tue, 13 Nov 2018 11:33:22 +0800 Subject: [PATCH] HBASE-21473 RowIndexSeekerV1 may return cell with extra two \x00\x00 bytes which has no tags --- .../hbase/io/encoding/RowIndexSeekerV1.java | 2 +- .../io/encoding/TestDataBlockEncoders.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexSeekerV1.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexSeekerV1.java index e1f00e27911..e4c48fa299f 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexSeekerV1.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexSeekerV1.java @@ -356,7 +356,7 @@ public class RowIndexSeekerV1 extends AbstractEncodedSeeker { protected int getCellBufSize() { int kvBufSize = KEY_VALUE_LEN_SIZE + keyLength + valueLength; - if (includesTags()) { + if (includesTags() && tagsLength > 0) { kvBufSize += Bytes.SIZEOF_SHORT + tagsLength; } return kvBufSize; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java index 5eb350f09da..5766517062b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java @@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.io.ByteArrayOutputStream; import org.apache.hadoop.hbase.io.compress.Compression; +import org.apache.hadoop.hbase.io.compress.Compression.Algorithm; import org.apache.hadoop.hbase.io.hfile.HFileContext; import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder; import org.apache.hadoop.hbase.nio.SingleByteBuff; @@ -50,6 +51,7 @@ import org.apache.hadoop.hbase.testclassification.IOTests; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.RedundantKVGenerator; +import org.junit.Assert; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -323,6 +325,29 @@ public class TestDataBlockEncoders { } } + @Test + public void testRowIndexWithTagsButNoTagsInCell() throws IOException { + List kvList = new ArrayList<>(); + byte[] row = new byte[0]; + byte[] family = new byte[0]; + byte[] qualifier = new byte[0]; + byte[] value = new byte[0]; + KeyValue expectedKV = new KeyValue(row, family, qualifier, -1L, Type.Put, value); + kvList.add(expectedKV); + DataBlockEncoding encoding = DataBlockEncoding.ROW_INDEX_V1; + DataBlockEncoder encoder = encoding.getEncoder(); + ByteBuffer encodedBuffer = + encodeKeyValues(encoding, kvList, getEncodingContext(Algorithm.NONE, encoding), false); + HFileContext meta = + new HFileContextBuilder().withHBaseCheckSum(false).withIncludesMvcc(includesMemstoreTS) + .withIncludesTags(includesTags).withCompression(Compression.Algorithm.NONE).build(); + DataBlockEncoder.EncodedSeeker seeker = encoder.createSeeker(CellComparatorImpl.COMPARATOR, + encoder.newDataBlockDecodingContext(meta)); + seeker.setCurrentBuffer(new SingleByteBuff(encodedBuffer)); + Cell cell = seeker.getCell(); + Assert.assertEquals(expectedKV.getLength(), ((KeyValue) cell).getLength()); + } + private void checkSeekingConsistency(List encodedSeekers, boolean seekBefore, Cell keyValue) { Cell expectedKeyValue = null;