Class ThreadLocalServerSideScanMetrics

java.lang.Object
org.apache.hadoop.hbase.monitoring.ThreadLocalServerSideScanMetrics

@Private public final class ThreadLocalServerSideScanMetrics extends Object
Thread-local storage for server-side scan metrics that captures performance data separately for each scan thread. This class works in conjunction with ServerSideScanMetrics to provide comprehensive scan performance monitoring.

Purpose and Design

ServerSideScanMetrics captures scan metrics on the server side and passes them back to the client in protocol buffer responses. However, the ServerSideScanMetrics instance is not readily available at deeper layers in HBase where HFiles are read and individual HFile blocks are accessed. To avoid the complexity of passing ServerSideScanMetrics instances through method calls across multiple layers, this class provides thread-local storage for metrics collection.

Thread Safety and HBase Architecture

This class leverages a critical aspect of HBase server design: on the server side, the thread that opens a RegionScanner and calls RegionScanner.nextRaw(java.util.List, ScannerContext) is the same thread that reads HFile blocks. This design allows thread-local storage to effectively capture metrics without cross-thread synchronization.

Special Handling for Parallel Operations

The only deviation from the single-thread model occurs when ParallelSeekHandler is used for parallel store file seeking. In this case, special handling ensures that metrics are captured correctly across multiple threads. The ParallelSeekHandler captures metrics from worker threads and aggregates them back to the main scan thread. Please refer to the javadoc of ParallelSeekHandler for detailed information about this parallel processing mechanism.

Usage Pattern

  1. Enable metrics collection: setScanMetricsEnabled(boolean)
  2. Reset counters at scan start: reset()
  3. Increment counters during I/O operations using the various add* methods
  4. Populate the main metrics object: populateServerSideScanMetrics(ServerSideScanMetrics)

Thread Safety

This class is thread-safe. Each thread maintains its own set of counters through ThreadLocal storage, ensuring that metrics from different scan operations do not interfere with each other.
See Also: