diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java index d873f7e7770..e8a1c3f71b3 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java @@ -122,7 +122,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { /** We need to store a copy of the key. */ protected byte[] keyBuffer = new byte[INITIAL_KEY_BUFFER_SIZE]; - protected byte[] tagsBuffer = new byte[INITIAL_KEY_BUFFER_SIZE]; + protected byte[] tagsBuffer = null; protected long memstoreTS; protected int nextKvOffset; @@ -132,9 +132,15 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { private final ObjectIntPair tmpPair; private final boolean includeTags; - public SeekerState(ObjectIntPair tmpPair, boolean includeTags) { + public SeekerState(ObjectIntPair tmpPair, boolean includeTags, + boolean tagsCompressed) { this.tmpPair = tmpPair; this.includeTags = includeTags; + if (tagsCompressed) { + tagsBuffer = new byte[INITIAL_KEY_BUFFER_SIZE]; + } else { + tagsBuffer = HConstants.EMPTY_BYTE_ARRAY; + } } protected boolean isValid() { @@ -724,6 +730,10 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { return this.decodingCtx.getHFileContext().isIncludesTags(); } + protected boolean tagsCompressed() { + return this.decodingCtx.getHFileContext().isCompressTags(); + } + @Override public int compareKey(CellComparator comparator, Cell key) { keyOnlyKV.setKey(current.keyBuffer, 0, current.keyLength); @@ -978,7 +988,8 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { protected STATE createSeekerState() { // This will fail for non-default seeker state if the subclass does not // override this method. - return (STATE) new SeekerState(this.tmpPair, this.includesTags()); + return (STATE) new SeekerState(this.tmpPair, this.includesTags(), + this.tagsCompressed()); } abstract protected void decodeFirst(); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java index fe9e518b9b9..0caf8e855c0 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java @@ -367,8 +367,9 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder { private int rowLengthWithSize; private long timestamp; - public DiffSeekerState(ObjectIntPair tmpPair, boolean includeTags) { - super(tmpPair, includeTags); + public DiffSeekerState(ObjectIntPair tmpPair, + boolean includeTags, boolean tagsCompressed) { + super(tmpPair, includeTags, tagsCompressed); } @Override @@ -503,7 +504,8 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder { @Override protected DiffSeekerState createSeekerState() { - return new DiffSeekerState(this.tmpPair, this.includesTags()); + return new DiffSeekerState(this.tmpPair, this.includesTags(), + this.tagsCompressed()); } }; } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java index b1f1965c049..b8b56ef2ea9 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java @@ -378,8 +378,9 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder { private int rowLengthWithSize; private int familyLengthWithSize; - public FastDiffSeekerState(ObjectIntPair tmpPair, boolean includeTags) { - super(tmpPair, includeTags); + public FastDiffSeekerState(ObjectIntPair tmpPair, + boolean includeTags, boolean tagsCompressed) { + super(tmpPair, includeTags, tagsCompressed); } @Override @@ -519,7 +520,8 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder { @Override protected FastDiffSeekerState createSeekerState() { - return new FastDiffSeekerState(this.tmpPair, this.includesTags()); + return new FastDiffSeekerState(this.tmpPair, this.includesTags(), + this.tagsCompressed()); } }; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java index 9e1bb64debc..d31fd0ce4c1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java @@ -21,16 +21,15 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteBuffer; +import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue.Type; -import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.IOTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ObjectIntPair; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.apache.hadoop.hbase.KeyValue; - @Category({IOTests.class, MediumTests.class}) public class TestBufferedDataBlockEncoder { @@ -49,8 +48,8 @@ public class TestBufferedDataBlockEncoder { @Test public void testEnsureSpaceForKey() { - BufferedDataBlockEncoder.SeekerState state = - new BufferedDataBlockEncoder.SeekerState(new ObjectIntPair(), false); + BufferedDataBlockEncoder.SeekerState state = new BufferedDataBlockEncoder.SeekerState( + new ObjectIntPair(), false, false); for (int i = 1; i <= 65536; ++i) { state.keyLength = i; state.ensureSpaceForKey();