HBASE-16502 Reduce garbage in BufferedDataBlockEncoder (binlijin)

This commit is contained in:
tedyu 2016-08-25 20:39:42 -07:00
parent c78a5fd650
commit b59f18c2af
4 changed files with 33 additions and 12 deletions

View File

@ -95,12 +95,20 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
/** We need to store a copy of the key. */ /** We need to store a copy of the key. */
protected byte[] keyBuffer = new byte[INITIAL_KEY_BUFFER_SIZE]; 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 long memstoreTS;
protected int nextKvOffset; protected int nextKvOffset;
protected KeyValue.KeyOnlyKeyValue currentKey = new KeyValue.KeyOnlyKeyValue(); protected KeyValue.KeyOnlyKeyValue currentKey = new KeyValue.KeyOnlyKeyValue();
public SeekerState(boolean tagsCompressed) {
if (tagsCompressed) {
tagsBuffer = new byte[INITIAL_KEY_BUFFER_SIZE];
} else {
tagsBuffer = HConstants.EMPTY_BYTE_ARRAY;
}
}
protected boolean isValid() { protected boolean isValid() {
return valueOffset != -1; return valueOffset != -1;
} }
@ -527,8 +535,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
protected final KVComparator comparator; protected final KVComparator comparator;
protected final SamePrefixComparator<byte[]> samePrefixComparator; protected final SamePrefixComparator<byte[]> samePrefixComparator;
protected ByteBuffer currentBuffer; protected ByteBuffer currentBuffer;
protected STATE current = createSeekerState(); // always valid protected STATE current, previous;
protected STATE previous = createSeekerState(); // may not be valid
protected TagCompressionContext tagCompressionContext = null; protected TagCompressionContext tagCompressionContext = null;
public BufferedEncodedSeeker(KVComparator comparator, public BufferedEncodedSeeker(KVComparator comparator,
@ -543,6 +550,8 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
throw new RuntimeException("Failed to initialize TagCompressionContext", e); throw new RuntimeException("Failed to initialize TagCompressionContext", e);
} }
} }
current = createSeekerState(); // always valid
previous = createSeekerState(); // may not be valid
} }
protected boolean includesMvcc() { protected boolean includesMvcc() {
@ -553,6 +562,10 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
return this.decodingCtx.getHFileContext().isIncludesTags(); return this.decodingCtx.getHFileContext().isIncludesTags();
} }
protected boolean tagsCompressed() {
return this.decodingCtx.getHFileContext().isCompressTags();
}
@Override @Override
public int compareKey(KVComparator comparator, byte[] key, int offset, int length) { public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
return comparator.compareFlatKey(key, offset, length, return comparator.compareFlatKey(key, offset, length,
@ -805,7 +818,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
protected STATE createSeekerState() { protected STATE createSeekerState() {
// This will fail for non-default seeker state if the subclass does not // This will fail for non-default seeker state if the subclass does not
// override this method. // override this method.
return (STATE) new SeekerState(); return (STATE) new SeekerState(this.tagsCompressed());
} }
abstract protected void decodeFirst(); abstract protected void decodeFirst();

View File

@ -21,12 +21,12 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.KeyValue.KVComparator; import org.apache.hadoop.hbase.KeyValue.KVComparator;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.util.ByteBufferUtils; import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
@ -362,6 +362,10 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
private int rowLengthWithSize; private int rowLengthWithSize;
private long timestamp; private long timestamp;
public DiffSeekerState(boolean tagsCompressed) {
super(tagsCompressed);
}
@Override @Override
protected void copyFromNext(SeekerState that) { protected void copyFromNext(SeekerState that) {
super.copyFromNext(that); super.copyFromNext(that);
@ -497,7 +501,7 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
@Override @Override
protected DiffSeekerState createSeekerState() { protected DiffSeekerState createSeekerState() {
return new DiffSeekerState(); return new DiffSeekerState(this.tagsCompressed());
} }
}; };
} }

View File

@ -21,12 +21,12 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.KeyValue.KVComparator; import org.apache.hadoop.hbase.KeyValue.KVComparator;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.util.ByteBufferUtils; import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
@ -379,6 +379,10 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
private int rowLengthWithSize; private int rowLengthWithSize;
private int familyLengthWithSize; private int familyLengthWithSize;
public FastDiffSeekerState(boolean tagsCompressed) {
super(tagsCompressed);
}
@Override @Override
protected void copyFromNext(SeekerState that) { protected void copyFromNext(SeekerState that) {
super.copyFromNext(that); super.copyFromNext(that);
@ -518,7 +522,7 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
@Override @Override
protected FastDiffSeekerState createSeekerState() { protected FastDiffSeekerState createSeekerState() {
return new FastDiffSeekerState(); return new FastDiffSeekerState(this.tagsCompressed());
} }
}; };
} }

View File

@ -27,8 +27,8 @@ public class TestBufferedDataBlockEncoder {
@Test @Test
public void testEnsureSpaceForKey() { public void testEnsureSpaceForKey() {
BufferedDataBlockEncoder.SeekerState state = BufferedDataBlockEncoder.SeekerState state = new BufferedDataBlockEncoder.SeekerState(
new BufferedDataBlockEncoder.SeekerState(); false);
for (int i = 1; i <= 65536; ++i) { for (int i = 1; i <= 65536; ++i) {
state.keyLength = i; state.keyLength = i;
state.ensureSpaceForKey(); state.ensureSpaceForKey();