Class ThreadLocalServerSideScanMetrics
java.lang.Object
org.apache.hadoop.hbase.monitoring.ThreadLocalServerSideScanMetrics
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 aRegionScanner
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 whenParallelSeekHandler
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
- Enable metrics collection:
setScanMetricsEnabled(boolean)
- Reset counters at scan start:
reset()
- Increment counters during I/O operations using the various
add*
methods - Populate the main metrics object:
populateServerSideScanMetrics(ServerSideScanMetrics)
Thread Safety
This class is thread-safe. Each thread maintains its own set of counters throughThreadLocal
storage, ensuring that metrics from different scan operations do not
interfere with each other.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ThreadLocal<AtomicLong>
private static final ThreadLocal<AtomicLong>
private static final ThreadLocal<AtomicLong>
private static final ThreadLocal<AtomicLong>
private static final ThreadLocal<Boolean>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
addBlockReadOpsCount
(long count) static long
addBytesReadFromBlockCache
(long bytes) static long
addBytesReadFromFs
(long bytes) static long
addBytesReadFromMemstore
(long bytes) static long
static AtomicLong
static long
static AtomicLong
static long
static AtomicLong
static long
static AtomicLong
static boolean
static void
static void
reset()
static void
setScanMetricsEnabled
(boolean enable)
-
Field Details
-
IS_SCAN_METRICS_ENABLED
-
BYTES_READ_FROM_FS
-
BYTES_READ_FROM_BLOCK_CACHE
-
BYTES_READ_FROM_MEMSTORE
-
BLOCK_READ_OPS_COUNT
-
-
Constructor Details
-
ThreadLocalServerSideScanMetrics
private ThreadLocalServerSideScanMetrics()
-
-
Method Details
-
setScanMetricsEnabled
-
addBytesReadFromFs
-
addBytesReadFromBlockCache
-
addBytesReadFromMemstore
-
addBlockReadOpsCount
-
isScanMetricsEnabled
-
getBytesReadFromFsCounter
-
getBytesReadFromBlockCacheCounter
-
getBytesReadFromMemstoreCounter
-
getBlockReadOpsCountCounter
-
getBytesReadFromFsAndReset
-
getBytesReadFromBlockCacheAndReset
-
getBytesReadFromMemstoreAndReset
-
getBlockReadOpsCountAndReset
-
reset
-
populateServerSideScanMetrics
-