4040import org .apache .hadoop .fs .FSDataInputStream ;
4141import org .apache .hadoop .fs .FSDataOutputStream ;
4242import org .apache .hadoop .hbase .Cell ;
43+ import org .apache .hadoop .hbase .HBaseInterfaceAudience ;
4344import org .apache .hadoop .hbase .HConstants ;
4445import org .apache .hadoop .hbase .fs .HFileSystem ;
4546import org .apache .hadoop .hbase .io .ByteArrayOutputStream ;
5556import org .apache .hadoop .hbase .io .encoding .HFileBlockEncodingContext ;
5657import org .apache .hadoop .hbase .io .hfile .trace .HFileContextAttributesBuilderConsumer ;
5758import org .apache .hadoop .hbase .io .util .BlockIOUtils ;
59+ import org .apache .hadoop .hbase .monitoring .ThreadLocalServerSideScanMetrics ;
5860import org .apache .hadoop .hbase .nio .ByteBuff ;
5961import org .apache .hadoop .hbase .nio .MultiByteBuff ;
6062import org .apache .hadoop .hbase .nio .SingleByteBuff ;
@@ -403,7 +405,8 @@ private static int getOnDiskSizeWithHeader(final ByteBuff headerBuf, boolean che
403405 * present) read by peeking into the next block's header; use as a hint when doing a read
404406 * of the next block when scanning or running over a file.
405407 */
406- int getNextBlockOnDiskSize () {
408+ @ InterfaceAudience .LimitedPrivate (HBaseInterfaceAudience .UNITTEST )
409+ public int getNextBlockOnDiskSize () {
407410 return nextBlockOnDiskSize ;
408411 }
409412
@@ -468,7 +471,8 @@ int getOnDiskSizeWithoutHeader() {
468471 }
469472
470473 /** Returns the uncompressed size of data part (header and checksum excluded). */
471- int getUncompressedSizeWithoutHeader () {
474+ @ InterfaceAudience .LimitedPrivate (HBaseInterfaceAudience .UNITTEST )
475+ public int getUncompressedSizeWithoutHeader () {
472476 return uncompressedSizeWithoutHeader ;
473477 }
474478
@@ -624,7 +628,8 @@ public String toString() {
624628 * Retrieves the decompressed/decrypted view of this block. An encoded block remains in its
625629 * encoded structure. Internal structures are shared between instances where applicable.
626630 */
627- HFileBlock unpack (HFileContext fileContext , FSReader reader ) throws IOException {
631+ @ InterfaceAudience .LimitedPrivate (HBaseInterfaceAudience .UNITTEST )
632+ public HFileBlock unpack (HFileContext fileContext , FSReader reader ) throws IOException {
628633 if (!fileContext .isCompressedOrEncrypted ()) {
629634 // TODO: cannot use our own fileContext here because HFileBlock(ByteBuffer, boolean),
630635 // which is used for block serialization to L2 cache, does not preserve encoding and
@@ -695,7 +700,8 @@ public boolean isUnpacked() {
695700 * when block is returned to the cache.
696701 * @return the offset of this block in the file it was read from
697702 */
698- long getOffset () {
703+ @ InterfaceAudience .LimitedPrivate (HBaseInterfaceAudience .UNITTEST )
704+ public long getOffset () {
699705 if (offset < 0 ) {
700706 throw new IllegalStateException ("HFile block offset not initialized properly" );
701707 }
@@ -1221,7 +1227,8 @@ interface BlockWritable {
12211227 * Iterator for reading {@link HFileBlock}s in load-on-open-section, such as root data index
12221228 * block, meta index block, file info block etc.
12231229 */
1224- interface BlockIterator {
1230+ @ InterfaceAudience .LimitedPrivate (HBaseInterfaceAudience .UNITTEST )
1231+ public interface BlockIterator {
12251232 /**
12261233 * Get the next block, or null if there are no more blocks to iterate.
12271234 */
@@ -1245,7 +1252,8 @@ interface BlockIterator {
12451252 }
12461253
12471254 /** An HFile block reader with iteration ability. */
1248- interface FSReader {
1255+ @ InterfaceAudience .LimitedPrivate (HBaseInterfaceAudience .UNITTEST )
1256+ public interface FSReader {
12491257 /**
12501258 * Reads the block at the given offset in the file with the given on-disk size and uncompressed
12511259 * size.
@@ -1720,6 +1728,7 @@ protected HFileBlock readBlockDataInternal(FSDataInputStream is, long offset,
17201728 // checksums. Can change with circumstances. The below flag is whether the
17211729 // file has support for checksums (version 2+).
17221730 boolean checksumSupport = this .fileContext .isUseHBaseChecksum ();
1731+ boolean isScanMetricsEnabled = ThreadLocalServerSideScanMetrics .isScanMetricsEnabled ();
17231732 long startTime = EnvironmentEdgeManager .currentTime ();
17241733 if (onDiskSizeWithHeader == -1 ) {
17251734 // The caller does not know the block size. Need to get it from the header. If header was
@@ -1736,6 +1745,9 @@ protected HFileBlock readBlockDataInternal(FSDataInputStream is, long offset,
17361745 headerBuf = HEAP .allocate (hdrSize );
17371746 readAtOffset (is , headerBuf , hdrSize , false , offset , pread );
17381747 headerBuf .rewind ();
1748+ if (isScanMetricsEnabled ) {
1749+ ThreadLocalServerSideScanMetrics .addBytesReadFromFs (hdrSize );
1750+ }
17391751 }
17401752 onDiskSizeWithHeader = getOnDiskSizeWithHeader (headerBuf , checksumSupport );
17411753 }
@@ -1783,6 +1795,12 @@ protected HFileBlock readBlockDataInternal(FSDataInputStream is, long offset,
17831795 boolean readNextHeader = readAtOffset (is , onDiskBlock ,
17841796 onDiskSizeWithHeader - preReadHeaderSize , true , offset + preReadHeaderSize , pread );
17851797 onDiskBlock .rewind (); // in case of moving position when copying a cached header
1798+ if (isScanMetricsEnabled ) {
1799+ long bytesRead =
1800+ (onDiskSizeWithHeader - preReadHeaderSize ) + (readNextHeader ? hdrSize : 0 );
1801+ ThreadLocalServerSideScanMetrics .addBytesReadFromFs (bytesRead );
1802+ ThreadLocalServerSideScanMetrics .addBlockReadOpsCount (1 );
1803+ }
17861804
17871805 // the call to validateChecksum for this block excludes the next block header over-read, so
17881806 // no reason to delay extracting this value.
0 commit comments