@@ -1385,6 +1385,13 @@ static class FSReaderImpl implements FSReader {
13851385
13861386 private final boolean isPreadAllBytes ;
13871387
1388+ private final long readWarnTime ;
1389+
1390+ /**
1391+ * If reading block cost time in milliseconds more than the threshold, a warning will be logged.
1392+ */
1393+ public static final String FS_READER_WARN_TIME_MS = "hbase.fs.reader.warn.time.ms" ;
1394+
13881395 FSReaderImpl (ReaderContext readerContext , HFileContext fileContext , ByteBuffAllocator allocator ,
13891396 Configuration conf ) throws IOException {
13901397 this .fileSize = readerContext .getFileSize ();
@@ -1402,6 +1409,8 @@ static class FSReaderImpl implements FSReader {
14021409 defaultDecodingCtx = new HFileBlockDefaultDecodingContext (conf , fileContext );
14031410 encodedBlockDecodingCtx = defaultDecodingCtx ;
14041411 isPreadAllBytes = readerContext .isPreadAllBytes ();
1412+ // Default warn threshold set to -1, it means skipping record the read block slow warning log.
1413+ readWarnTime = conf .getLong (FS_READER_WARN_TIME_MS , -1L );
14051414 }
14061415
14071416 @ Override
@@ -1759,6 +1768,10 @@ protected HFileBlock readBlockDataInternal(FSDataInputStream is, long offset,
17591768 hFileBlock .sanityCheckUncompressed ();
17601769 }
17611770 LOG .trace ("Read {} in {} ms" , hFileBlock , duration );
1771+ if (!LOG .isTraceEnabled () && this .readWarnTime >= 0 && duration > this .readWarnTime ) {
1772+ LOG .warn ("Read Block Slow: read {} cost {} ms, threshold = {} ms" , hFileBlock , duration ,
1773+ this .readWarnTime );
1774+ }
17621775 span .addEvent ("Read block" , attributesBuilder .build ());
17631776 // Cache next block header if we read it for the next time through here.
17641777 if (nextBlockOnDiskSize != -1 ) {
0 commit comments