Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-26731 Add metrics for active and expired scanners #4145

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
*/
void updateCompactionOutputSize(boolean isMajor, long bytes);

void incrScannerLeaseExpired();

// Strings used for exporting to metrics system.
String REGION_COUNT = "regionCount";
String REGION_COUNT_DESC = "Number of regions";
Expand Down Expand Up @@ -598,4 +600,10 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
String BYTE_BUFF_ALLOCATOR_TOTAL_BUFFER_COUNT_DESC = "Total buffer count in ByteBuffAllocator";
String BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT = "ByteBuffAllocatorUsedBufferCount";
String BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT_DESC = "Used buffer count in ByteBuffAllocator";

String ACTIVE_SCANNERS = "activeScanners";
String ACTIVE_SCANNERS_DESC = "Gauge of currently active scanners";

String SCANNER_LEASE_EXPIRED_COUNT = "scannerLeaseExpiredCount";
String SCANNER_LEASE_EXPIRED_COUNT_DESC = "Count of scanners which were expired due to scanner lease timeout";
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class MetricsRegionServerSourceImpl
private final MetricHistogram pausesWithGc;
private final MetricHistogram pausesWithoutGc;

private final MutableFastCounter scannerLeaseExpiredCount;

public MetricsRegionServerSourceImpl(MetricsRegionServerWrapper rsWrap) {
this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT, rsWrap);
}
Expand Down Expand Up @@ -179,6 +181,8 @@ public MetricsRegionServerSourceImpl(String metricsName,
WARN_THRESHOLD_COUNT_DESC, 0L);
pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY);
pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY);

scannerLeaseExpiredCount = getMetricsRegistry().newCounter(SCANNER_LEASE_EXPIRED_COUNT, SCANNER_LEASE_EXPIRED_COUNT_DESC, 0L);
}

@Override
Expand Down Expand Up @@ -322,6 +326,11 @@ public void updateCompactionOutputSize(boolean isMajor, long bytes) {
}
}

@Override
public void incrScannerLeaseExpired() {
scannerLeaseExpiredCount.incr();
}

/**
* Yes this is a get function that doesn't return anything. Thanks Hadoop for breaking all
* expectations of java programmers. Instead of returning anything Hadoop metrics expects
Expand Down Expand Up @@ -586,7 +595,9 @@ private MetricsRecordBuilder addGaugesToMetricsRecordBuilder(MetricsRecordBuilde
rsWrap.getByteBuffAllocatorTotalBufferCount())
.addGauge(Interns.info(BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT,
BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT_DESC),
rsWrap.getByteBuffAllocatorUsedBufferCount());
rsWrap.getByteBuffAllocatorUsedBufferCount())
.addGauge(Interns.info(ACTIVE_SCANNERS, ACTIVE_SCANNERS_DESC),
rsWrap.getActiveScanners());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,6 @@ public interface MetricsRegionServerWrapper {
long getByteBuffAllocatorTotalBufferCount();

long getByteBuffAllocatorUsedBufferCount();

int getActiveScanners();
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,8 @@ public void updateWriteQueryMeter(TableName tn) {
serverWriteQueryMeter.mark();
}
}

public void incrScannerLeaseExpired() {
serverSource.incrScannerLeaseExpired();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ public double getMobFileCacheHitPercent() {
return mobFileCacheHitRatio * 100;
}

@Override
public int getActiveScanners() {
return regionServer.getRpcServices().getScannersCount();
}

/**
* This is the runnable that will be executed on the executor every PERIOD number of seconds
* It will take metrics/numbers from all of the regions and use them to compute point in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ public void leaseExpired() {
return;
}
LOG.info("Scanner lease {} expired {}", this.scannerName, rsh);
server.getMetrics().incrScannerLeaseExpired();
RegionScanner s = rsh.s;
HRegion region = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public long getByteBuffAllocatorUsedBufferCount() {
return 0;
}

@Override
public int getActiveScanners() {
return 0;
}

@Override
public long getReadRequestsCount() {
return 997;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ public void testPauseMonitor() {
HELPER.assertCounter("pauseTimeWithGc_num_ops", 1, serverSource);
}

@Test
public void testScannerMetrics() {
HELPER.assertCounter("scannerLeaseExpiredCount", 0, serverSource);
rsm.incrScannerLeaseExpired();
HELPER.assertCounter("scannerLeaseExpiredCount", 1, serverSource);
HELPER.assertGauge("activeScanners", 0, serverSource);
}

@Test
public void testTableQueryMeterSwitch() {
TableName tn1 = TableName.valueOf("table1");
Expand Down