HBASE-27888 Record readBlock message in log when it takes too long time

This commit is contained in:
chaijunjie0101 2023-05-26 20:43:21 +08:00
parent f347867440
commit 08335cd4fc
1 changed files with 13 additions and 0 deletions

View File

@ -1385,6 +1385,13 @@ public class HFileBlock implements Cacheable {
private final boolean isPreadAllBytes; private final boolean isPreadAllBytes;
private final long readWarnTime;
/**
* If reading block cost time in milliseconds more than the threshold, a warning will be logged.
*/
public static final String FS_READER_WARN_TIME_MS = "hbase.fs.reader.warn.time.ms";
FSReaderImpl(ReaderContext readerContext, HFileContext fileContext, ByteBuffAllocator allocator, FSReaderImpl(ReaderContext readerContext, HFileContext fileContext, ByteBuffAllocator allocator,
Configuration conf) throws IOException { Configuration conf) throws IOException {
this.fileSize = readerContext.getFileSize(); this.fileSize = readerContext.getFileSize();
@ -1402,6 +1409,8 @@ public class HFileBlock implements Cacheable {
defaultDecodingCtx = new HFileBlockDefaultDecodingContext(conf, fileContext); defaultDecodingCtx = new HFileBlockDefaultDecodingContext(conf, fileContext);
encodedBlockDecodingCtx = defaultDecodingCtx; encodedBlockDecodingCtx = defaultDecodingCtx;
isPreadAllBytes = readerContext.isPreadAllBytes(); isPreadAllBytes = readerContext.isPreadAllBytes();
// Default warn threshold set to -1, it means skipping record the read block slow warning log.
readWarnTime = conf.getLong(FS_READER_WARN_TIME_MS, -1L);
} }
@Override @Override
@ -1759,6 +1768,10 @@ public class HFileBlock implements Cacheable {
hFileBlock.sanityCheckUncompressed(); hFileBlock.sanityCheckUncompressed();
} }
LOG.trace("Read {} in {} ms", hFileBlock, duration); LOG.trace("Read {} in {} ms", hFileBlock, duration);
if (!LOG.isTraceEnabled() && this.readWarnTime >= 0 && duration > this.readWarnTime) {
LOG.warn("Read Block Slow: read {} cost {} ms, threshold = {} ms", hFileBlock, duration,
this.readWarnTime);
}
span.addEvent("Read block", attributesBuilder.build()); span.addEvent("Read block", attributesBuilder.build());
// Cache next block header if we read it for the next time through here. // Cache next block header if we read it for the next time through here.
if (nextBlockOnDiskSize != -1) { if (nextBlockOnDiskSize != -1) {