HBASE-16738 L1 cache caching shared memory HFile block when blocks promoted from L2 to L1.

This commit is contained in:
anoopsamjohn 2016-10-03 16:04:48 +05:30
parent ec0adbd2c0
commit 250ad644e4
2 changed files with 20 additions and 1 deletions

View File

@ -300,11 +300,23 @@ public class HFileBlock implements Cacheable {
* Copy constructor. Creates a shallow copy of {@code that}'s buffer.
*/
private HFileBlock(HFileBlock that) {
this(that, false);
}
/**
* Copy constructor. Creates a shallow/deep copy of {@code that}'s buffer as per the boolean
* param.
*/
private HFileBlock(HFileBlock that,boolean bufCopy) {
this.blockType = that.blockType;
this.onDiskSizeWithoutHeader = that.onDiskSizeWithoutHeader;
this.uncompressedSizeWithoutHeader = that.uncompressedSizeWithoutHeader;
this.prevBlockOffset = that.prevBlockOffset;
this.buf = that.buf.duplicate();
if (bufCopy) {
this.buf = new SingleByteBuff(ByteBuffer.wrap(that.buf.toBytes(0, that.buf.limit())));
} else {
this.buf = that.buf.duplicate();
}
this.offset = that.offset;
this.onDiskDataSizeWithHeader = that.onDiskDataSizeWithHeader;
this.fileContext = that.fileContext;
@ -2015,4 +2027,8 @@ public class HFileBlock implements Cacheable {
" bytesPerChecksum " + bytesPerChecksum +
" onDiskDataSizeWithHeader " + onDiskDataSizeWithHeader;
}
public HFileBlock deepClone() {
return new HFileBlock(this, true);
}
}

View File

@ -479,6 +479,9 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
// Promote this to L1.
if (result != null && caching) {
if (result instanceof HFileBlock && ((HFileBlock) result).usesSharedMemory()) {
result = ((HFileBlock) result).deepClone();
}
cacheBlock(cacheKey, result, /* inMemory = */ false, /* cacheData = */ true);
}
return result;