-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HBASE-28596 Optimise BucketCache usage upon regions splits/merges. #5906
Changes from all commits
3d71529
7bf567f
1f9d91f
61a12fc
8bb7507
ca03c50
96ebf97
3c87622
4587713
64b0855
243df04
7dba9bf
a23ca87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
*/ | ||
package org.apache.hadoop.hbase.io.hfile; | ||
|
||
import static org.apache.hadoop.hbase.io.hfile.HFileBlock.FILL_HEADER; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.util.NavigableMap; | ||
|
@@ -25,7 +27,9 @@ | |
import java.util.concurrent.ConcurrentSkipListSet; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hbase.metrics.impl.FastLongHistogram; | ||
import org.apache.hadoop.hbase.nio.ByteBuff; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.apache.hadoop.hbase.util.ChecksumType; | ||
import org.apache.hadoop.hbase.util.GsonUtil; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.slf4j.Logger; | ||
|
@@ -244,6 +248,44 @@ public static int getMaxCachedBlocksByFile(Configuration conf) { | |
return conf == null ? DEFAULT_MAX : conf.getInt("hbase.ui.blockcache.by.file.max", DEFAULT_MAX); | ||
} | ||
|
||
/** | ||
* Similarly to HFileBlock.Writer.getBlockForCaching(), creates a HFileBlock instance without | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we share some common code between these two methods? Otherwise how can we align these two methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, let me work on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the most I could reuse here is the new HFIleContext part. The block builder portion is hard to reuse because in HFileBlock.Writer the parameters are calculated on the go, so any sort of reuse would require an awful lot of parameters. |
||
* checksum for caching. This is needed for when we cache blocks via readers (either prefetch or | ||
* client read), otherwise we may fail equality comparison when checking against same block that | ||
* may already have been cached at write time. | ||
* @param cacheConf the related CacheConfig object. | ||
* @param block the HFileBlock instance to be converted. | ||
* @return the resulting HFileBlock instance without checksum. | ||
*/ | ||
public static HFileBlock getBlockForCaching(CacheConfig cacheConf, HFileBlock block) { | ||
// Calculate how many bytes we need for checksum on the tail of the block. | ||
int numBytes = cacheConf.shouldCacheCompressed(block.getBlockType().getCategory()) | ||
? 0 | ||
: (int) ChecksumUtil.numBytes(block.getOnDiskDataSizeWithHeader(), | ||
block.getHFileContext().getBytesPerChecksum()); | ||
ByteBuff buff = block.getBufferReadOnly(); | ||
HFileBlockBuilder builder = new HFileBlockBuilder(); | ||
return builder.withBlockType(block.getBlockType()) | ||
.withOnDiskSizeWithoutHeader(block.getOnDiskSizeWithoutHeader()) | ||
.withUncompressedSizeWithoutHeader(block.getUncompressedSizeWithoutHeader()) | ||
.withPrevBlockOffset(block.getPrevBlockOffset()).withByteBuff(buff) | ||
.withFillHeader(FILL_HEADER).withOffset(block.getOffset()).withNextBlockOnDiskSize(-1) | ||
.withOnDiskDataSizeWithHeader(block.getOnDiskDataSizeWithHeader() + numBytes) | ||
.withHFileContext(cloneContext(block.getHFileContext())) | ||
.withByteBuffAllocator(cacheConf.getByteBuffAllocator()).withShared(!buff.hasArray()).build(); | ||
} | ||
|
||
public static HFileContext cloneContext(HFileContext context) { | ||
HFileContext newContext = new HFileContextBuilder().withBlockSize(context.getBlocksize()) | ||
.withBytesPerCheckSum(0).withChecksumType(ChecksumType.NULL) // no checksums in cached data | ||
.withCompression(context.getCompression()) | ||
.withDataBlockEncoding(context.getDataBlockEncoding()) | ||
.withHBaseCheckSum(context.isUseHBaseChecksum()).withCompressTags(context.isCompressTags()) | ||
.withIncludesMvcc(context.isIncludesMvcc()).withIncludesTags(context.isIncludesTags()) | ||
.withColumnFamily(context.getColumnFamily()).withTableName(context.getTableName()).build(); | ||
return newContext; | ||
} | ||
|
||
/** | ||
* Use one of these to keep a running account of cached blocks by file. Throw it away when done. | ||
* This is different than metrics in that it is stats on current state of a cache. See | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ public HFilePreadReader(ReaderContext context, HFileInfo fileInfo, CacheConfig c | |
}); | ||
|
||
// Prefetch file blocks upon open if requested | ||
if (cacheConf.shouldPrefetchOnOpen() && cacheIfCompactionsOff() && shouldCache.booleanValue()) { | ||
if (cacheConf.shouldPrefetchOnOpen() && shouldCache.booleanValue()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why removing cacheIfCompactionsOff? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason as explained here: https://github.com/apache/hbase/pull/5906/files#r1606971440. We want the prefetch to run even for refs or links, the cache implementation should decide what to do with refs/links. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better add some comments to explain the history here? |
||
PrefetchExecutor.request(path, new Runnable() { | ||
@Override | ||
public void run() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually it is not a good idea to the implementation class directly at upper layer. Why we need to use HFileScannerImpl here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to seek to the split cell, in order to calculate offsets for the cache keys of referred file to evict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there is a seekTo method in HFileScanner interface? I just mean why we need the cast here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need the HFileScannerImpl.getCurBlock for figuring out the offset.