Skip to content

Commit f305516

Browse files
HBASE-27888 Record readBlock message in log when it takes too long time
1 parent f347867 commit f305516

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,13 @@ public enum OperationStatusCode {
16031603
*/
16041604
public final static boolean HBASE_SERVER_USEIP_ENABLED_DEFAULT = false;
16051605

1606+
/**
1607+
* If reading block cost time more than the threshold, a warning will be logged.
1608+
*/
1609+
public static final String FS_READER_WARN_TIME = "hbase.fs.reader.warn.time";
1610+
1611+
public static final long DEFAULT_FS_READER_WARN_TIME = 100L;
1612+
16061613
private HConstants() {
16071614
// Can't be instantiated with this ctor.
16081615
}

hbase-common/src/main/resources/hbase-default.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,4 +2062,9 @@ possible configurations would overwhelm and obscure the important.
20622062
hitting the namenode, if the DFSInputStream's block list is incomplete.
20632063
</description>
20642064
</property>
2065+
<property>
2066+
<name>hbase.fs.reader.warn.time</name>
2067+
<value>100</value>
2068+
<description>Record slow read block in warning log, in milliseconds.</description>
2069+
</property>
20652070
</configuration>

hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,8 @@ static class FSReaderImpl implements FSReader {
13851385

13861386
private final boolean isPreadAllBytes;
13871387

1388+
private final long readWarnTime;
1389+
13881390
FSReaderImpl(ReaderContext readerContext, HFileContext fileContext, ByteBuffAllocator allocator,
13891391
Configuration conf) throws IOException {
13901392
this.fileSize = readerContext.getFileSize();
@@ -1402,6 +1404,8 @@ static class FSReaderImpl implements FSReader {
14021404
defaultDecodingCtx = new HFileBlockDefaultDecodingContext(conf, fileContext);
14031405
encodedBlockDecodingCtx = defaultDecodingCtx;
14041406
isPreadAllBytes = readerContext.isPreadAllBytes();
1407+
readWarnTime =
1408+
conf.getLong(HConstants.FS_READER_WARN_TIME, HConstants.DEFAULT_FS_READER_WARN_TIME);
14051409
}
14061410

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

0 commit comments

Comments
 (0)