HBASE-16502 Reduce garbage in BufferedDataBlockEncoder - addendum adopts Hiroshi's suggestion (binlijin)

This commit is contained in:
tedyu 2016-08-30 18:06:24 -07:00
parent 57c6384b09
commit 9907a7e2a2
4 changed files with 15 additions and 31 deletions

View File

@ -94,19 +94,14 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
protected boolean uncompressTags = true;
/** We need to store a copy of the key. */
protected byte[] keyBuffer = new byte[INITIAL_KEY_BUFFER_SIZE];
protected byte[] tagsBuffer = null;
protected byte[] keyBuffer = HConstants.EMPTY_BYTE_ARRAY;
protected byte[] tagsBuffer = HConstants.EMPTY_BYTE_ARRAY;
protected long memstoreTS;
protected int nextKvOffset;
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;
}
public SeekerState() {
}
protected boolean isValid() {
@ -123,11 +118,8 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
protected void ensureSpaceForKey() {
if (keyLength > keyBuffer.length) {
// rare case, but we need to handle arbitrary length of key
int newKeyBufferLength = Math.max(keyBuffer.length, 1) * 2;
while (keyLength > newKeyBufferLength) {
newKeyBufferLength *= 2;
}
int newKeyBufferLength = Integer.highestOneBit(Math.max(
INITIAL_KEY_BUFFER_SIZE, keyLength) - 1) << 1;
byte[] newKeyBuffer = new byte[newKeyBufferLength];
System.arraycopy(keyBuffer, 0, newKeyBuffer, 0, keyBuffer.length);
keyBuffer = newKeyBuffer;
@ -136,11 +128,8 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
protected void ensureSpaceForTags() {
if (tagsLength > tagsBuffer.length) {
// rare case, but we need to handle arbitrary length of tags
int newTagsBufferLength = Math.max(tagsBuffer.length, 1) * 2;
while (tagsLength > newTagsBufferLength) {
newTagsBufferLength *= 2;
}
int newTagsBufferLength = Integer.highestOneBit(Math.max(
INITIAL_KEY_BUFFER_SIZE, tagsLength) - 1) << 1;
byte[] newTagsBuffer = new byte[newTagsBufferLength];
System.arraycopy(tagsBuffer, 0, newTagsBuffer, 0, tagsBuffer.length);
tagsBuffer = newTagsBuffer;
@ -562,10 +551,6 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
return this.decodingCtx.getHFileContext().isIncludesTags();
}
protected boolean tagsCompressed() {
return this.decodingCtx.getHFileContext().isCompressTags();
}
@Override
public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
return comparator.compareFlatKey(key, offset, length,
@ -818,7 +803,7 @@ 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.tagsCompressed());
return (STATE) new SeekerState();
}
abstract protected void decodeFirst();

View File

@ -362,8 +362,8 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
private int rowLengthWithSize;
private long timestamp;
public DiffSeekerState(boolean tagsCompressed) {
super(tagsCompressed);
public DiffSeekerState() {
super();
}
@Override
@ -501,7 +501,7 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
@Override
protected DiffSeekerState createSeekerState() {
return new DiffSeekerState(this.tagsCompressed());
return new DiffSeekerState();
}
};
}

View File

@ -379,8 +379,8 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
private int rowLengthWithSize;
private int familyLengthWithSize;
public FastDiffSeekerState(boolean tagsCompressed) {
super(tagsCompressed);
public FastDiffSeekerState() {
super();
}
@Override
@ -522,7 +522,7 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
@Override
protected FastDiffSeekerState createSeekerState() {
return new FastDiffSeekerState(this.tagsCompressed());
return new FastDiffSeekerState();
}
};
}

View File

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