HBASE-21473 RowIndexSeekerV1 may return cell with extra two \x00\x00 bytes which has no tags

This commit is contained in:
huzheng 2018-11-13 11:33:22 +08:00
parent 814c3690dc
commit 9cef4e1141
2 changed files with 28 additions and 1 deletions

View File

@ -387,7 +387,7 @@ public class RowIndexSeekerV1 extends AbstractEncodedSeeker {
protected int getCellBufSize() { protected int getCellBufSize() {
int kvBufSize = KEY_VALUE_LEN_SIZE + keyLength + valueLength; int kvBufSize = KEY_VALUE_LEN_SIZE + keyLength + valueLength;
if (includesTags()) { if (includesTags() && tagsLength > 0) {
kvBufSize += Bytes.SIZEOF_SHORT + tagsLength; kvBufSize += Bytes.SIZEOF_SHORT + tagsLength;
} }
return kvBufSize; return kvBufSize;

View File

@ -32,6 +32,7 @@ import java.util.Random;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.CategoryBasedTimeout; import org.apache.hadoop.hbase.CategoryBasedTimeout;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
@ -40,11 +41,13 @@ import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.io.ByteArrayOutputStream; import org.apache.hadoop.hbase.io.ByteArrayOutputStream;
import org.apache.hadoop.hbase.io.compress.Compression; 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.HFileContext;
import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder; import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder;
import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.RedundantKVGenerator; import org.apache.hadoop.hbase.util.RedundantKVGenerator;
import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@ -430,4 +433,28 @@ public class TestDataBlockEncoders {
assertEquals("Encoding -> decoding gives different results for " + encoder, assertEquals("Encoding -> decoding gives different results for " + encoder,
Bytes.toStringBinary(unencodedDataBuf), Bytes.toStringBinary(actualDataset)); Bytes.toStringBinary(unencodedDataBuf), Bytes.toStringBinary(actualDataset));
} }
@Test
public void testRowIndexWithTagsButNoTagsInCell() throws IOException {
List<KeyValue> 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));
HFileContext meta =
new HFileContextBuilder().withHBaseCheckSum(false).withIncludesMvcc(includesMemstoreTS)
.withIncludesTags(includesTags).withCompression(Compression.Algorithm.NONE).build();
DataBlockEncoder.EncodedSeeker seeker =
encoder.createSeeker(KeyValue.COMPARATOR, encoder.newDataBlockDecodingContext(meta));
seeker.setCurrentBuffer(encodedBuffer);
Cell cell = seeker.getKeyValue();
Assert.assertEquals(expectedKV.getLength(), ((KeyValue) cell).getLength());
}
} }