Skip to content

Commit

Permalink
HBASE-27888 Record readBlock message in log when it takes too long time
Browse files Browse the repository at this point in the history
  • Loading branch information
chaijunjie0101 committed May 26, 2023
1 parent f347867 commit f305516
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,13 @@ public enum OperationStatusCode {
*/
public final static boolean HBASE_SERVER_USEIP_ENABLED_DEFAULT = false;

/**
* If reading block cost time more than the threshold, a warning will be logged.
*/
public static final String FS_READER_WARN_TIME = "hbase.fs.reader.warn.time";

public static final long DEFAULT_FS_READER_WARN_TIME = 100L;

private HConstants() {
// Can't be instantiated with this ctor.
}
Expand Down
5 changes: 5 additions & 0 deletions hbase-common/src/main/resources/hbase-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2062,4 +2062,9 @@ possible configurations would overwhelm and obscure the important.
hitting the namenode, if the DFSInputStream's block list is incomplete.
</description>
</property>
<property>
<name>hbase.fs.reader.warn.time</name>
<value>100</value>
<description>Record slow read block in warning log, in milliseconds.</description>
</property>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,8 @@ static class FSReaderImpl implements FSReader {

private final boolean isPreadAllBytes;

private final long readWarnTime;

FSReaderImpl(ReaderContext readerContext, HFileContext fileContext, ByteBuffAllocator allocator,
Configuration conf) throws IOException {
this.fileSize = readerContext.getFileSize();
Expand All @@ -1402,6 +1404,8 @@ static class FSReaderImpl implements FSReader {
defaultDecodingCtx = new HFileBlockDefaultDecodingContext(conf, fileContext);
encodedBlockDecodingCtx = defaultDecodingCtx;
isPreadAllBytes = readerContext.isPreadAllBytes();
readWarnTime =
conf.getLong(HConstants.FS_READER_WARN_TIME, HConstants.DEFAULT_FS_READER_WARN_TIME);
}

@Override
Expand Down Expand Up @@ -1759,6 +1763,10 @@ protected HFileBlock readBlockDataInternal(FSDataInputStream is, long offset,
hFileBlock.sanityCheckUncompressed();
}
LOG.trace("Read {} in {} ms", hFileBlock, duration);
if (!LOG.isTraceEnabled() && duration > this.readWarnTime) {
LOG.warn("Read Block Slow: read {} cost {} ms, threshold = {} ms", hFileBlock, duration,
this.readWarnTime);
}
span.addEvent("Read block", attributesBuilder.build());
// Cache next block header if we read it for the next time through here.
if (nextBlockOnDiskSize != -1) {
Expand Down

0 comments on commit f305516

Please sign in to comment.