diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSource.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSource.java index 518709e63c7..e5c79adedd4 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSource.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSource.java @@ -87,6 +87,13 @@ public interface MetricsRegionServerSource extends BaseSource { */ void updateReplay(long t); + /** + * Update the scan size. + * + * @param scanSize size of the scan + */ + void updateScannerNext(long scanSize); + /** * Increment the number of slow Puts that have happened. */ diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java index 0c9e7dcadd4..fab2a49bcd2 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java @@ -42,6 +42,7 @@ public class MetricsRegionServerSourceImpl private final MetricHistogram incrementHisto; private final MetricHistogram appendHisto; private final MetricHistogram replayHisto; + private final MetricHistogram scanNextHisto; private final MutableCounterLong slowPut; private final MutableCounterLong slowDelete; @@ -82,6 +83,7 @@ public class MetricsRegionServerSourceImpl slowAppend = getMetricsRegistry().newCounter(SLOW_APPEND_KEY, SLOW_APPEND_DESC, 0l); replayHisto = getMetricsRegistry().newHistogram(REPLAY_KEY); + scanNextHisto = getMetricsRegistry().newHistogram(SCAN_NEXT_KEY); splitTimeHisto = getMetricsRegistry().newHistogram(SPLIT_KEY); flushTimeHisto = getMetricsRegistry().newHistogram(FLUSH_KEY); @@ -120,6 +122,11 @@ public class MetricsRegionServerSourceImpl replayHisto.add(t); } + @Override + public void updateScannerNext(long scanSize) { + scanNextHisto.add(scanSize); + } + @Override public void incrSlowPut() { slowPut.incr(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServer.java index c3bf97e0708..9f98ba6b43e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServer.java @@ -95,6 +95,10 @@ public class MetricsRegionServer { serverSource.updateReplay(t); } + public void updateScannerNext(long scanSize){ + serverSource.updateScannerNext(scanSize); + } + public void updateSplitTime(long t) { serverSource.updateSplitTime(t); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java index b0fd9eb72de..a0761ec13ea 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java @@ -2294,6 +2294,9 @@ public class RSRpcServices implements HBaseRPCErrorHandler, } region.updateReadRequestsCount(i); region.getMetrics().updateScanNext(totalCellSize); + if (regionServer.metricsRegionServer != null) { + regionServer.metricsRegionServer.updateScannerNext(totalCellSize); + } } finally { region.closeRegionOperation(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java index 3767513b2aa..d8135758b74 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java @@ -53,6 +53,8 @@ public class TestRegionServerMetrics { private static HBaseTestingUtility TEST_UTIL; private static MetricsRegionServer metricsRegionServer; private static MetricsRegionServerSource serverSource; + private static final int NUM_SCAN_NEXT = 30; + private static int numScanNext = 0; @BeforeClass public static void startCluster() throws Exception { @@ -329,7 +331,6 @@ public class TestRegionServerMetrics { byte[] qualifier = Bytes.toBytes("qual"); byte[] val = Bytes.toBytes("One"); - List puts = new ArrayList<>(); for (int insertCount =0; insertCount < 100; insertCount++) { Put p = new Put(Bytes.toBytes("" + insertCount + "row")); @@ -344,12 +345,13 @@ public class TestRegionServerMetrics { s.setCaching(1); ResultScanner resultScanners = t.getScanner(s); - for (int nextCount = 0; nextCount < 30; nextCount++) { + for (int nextCount = 0; nextCount < NUM_SCAN_NEXT; nextCount++) { Result result = resultScanners.next(); assertNotNull(result); assertEquals(1, result.size()); } } + numScanNext += NUM_SCAN_NEXT; try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) { for ( HRegionLocation location: locator.getAllRegionLocations()) { HRegionInfo i = location.getRegionInfo(); @@ -361,8 +363,55 @@ public class TestRegionServerMetrics { "_table_"+tableNameString + "_region_" + i.getEncodedName()+ "_metric"; - metricsHelper.assertCounter(prefix + "_scanNextNumOps", 30, agg); + metricsHelper.assertCounter(prefix + "_scanNextNumOps", NUM_SCAN_NEXT, agg); } + metricsHelper.assertCounter("ScanNext_num_ops", numScanNext, serverSource); + } + } + + @Test + public void testScanNextForSmallScan() throws IOException { + String tableNameString = "testScanNextSmall"; + TableName tableName = TableName.valueOf(tableNameString); + byte[] cf = Bytes.toBytes("d"); + byte[] qualifier = Bytes.toBytes("qual"); + byte[] val = Bytes.toBytes("One"); + + List puts = new ArrayList<>(); + for (int insertCount =0; insertCount < 100; insertCount++) { + Put p = new Put(Bytes.toBytes("" + insertCount + "row")); + p.add(cf, qualifier, val); + puts.add(p); + } + try (HTable t = TEST_UTIL.createTable(tableName, cf)) { + t.put(puts); + + Scan s = new Scan(); + s.setSmall(true); + s.setCaching(1); + ResultScanner resultScanners = t.getScanner(s); + + for (int nextCount = 0; nextCount < NUM_SCAN_NEXT; nextCount++) { + Result result = resultScanners.next(); + assertNotNull(result); + assertEquals(1, result.size()); + } + } + numScanNext += NUM_SCAN_NEXT; + try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) { + for ( HRegionLocation location: locator.getAllRegionLocations()) { + HRegionInfo i = location.getRegionInfo(); + MetricsRegionAggregateSource agg = rs.getRegion(i.getRegionName()) + .getMetrics() + .getSource() + .getAggregateSource(); + String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+ + "_table_"+tableNameString + + "_region_" + i.getEncodedName()+ + "_metric"; + metricsHelper.assertCounter(prefix + "_scanNextNumOps", NUM_SCAN_NEXT, agg); + } + metricsHelper.assertCounter("ScanNext_num_ops", numScanNext, serverSource); } } }