From e5d4e2fc8138cba0c4a1da2b42b51042da3d9c7e Mon Sep 17 00:00:00 2001 From: Reid Chan Date: Sun, 25 Oct 2020 17:46:14 +0800 Subject: [PATCH] HBASE-25189 [Metrics] Add checkAndPut and checkAndDelete latency metrics at table level (#2549) Signed-off-by: Viraj Jasani --- .../regionserver/MetricsTableLatencies.java | 25 +++++++++++++ .../MetricsTableLatenciesImpl.java | 36 +++++++++++++++++++ .../regionserver/MetricsRegionServer.java | 15 ++++++-- .../hbase/regionserver/RSRpcServices.java | 9 +++-- .../RegionServerTableMetrics.java | 12 +++++++ .../regionserver/TestMetricsRegionServer.java | 17 ++------- 6 files changed, 94 insertions(+), 20 deletions(-) diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableLatencies.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableLatencies.java index 231bad1be87..2aeb82b0d64 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableLatencies.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableLatencies.java @@ -53,6 +53,9 @@ public interface MetricsTableLatencies { String DELETE_BATCH_TIME = "deleteBatchTime"; String INCREMENT_TIME = "incrementTime"; String APPEND_TIME = "appendTime"; + String CHECK_AND_DELETE_TIME = "checkAndDeleteTime"; + String CHECK_AND_PUT_TIME = "checkAndPutTime"; + String CHECK_AND_MUTATE_TIME = "checkAndMutateTime"; /** * Update the Put time histogram @@ -125,4 +128,26 @@ public interface MetricsTableLatencies { * @param t time it took */ void updateScanTime(String tableName, long t); + + /** + * Update the CheckAndDelete time histogram. + * @param nameAsString The table the metric is for + * @param time time it took + */ + void updateCheckAndDelete(String nameAsString, long time); + + /** + * Update the CheckAndPut time histogram. + * @param nameAsString The table the metric is for + * @param time time it took + */ + void updateCheckAndPut(String nameAsString, long time); + + /** + * Update the CheckAndMutate time histogram. + * @param nameAsString The table the metric is for + * @param time time it took + */ + void updateCheckAndMutate(String nameAsString, long time); + } diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableLatenciesImpl.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableLatenciesImpl.java index 5a3f3b9d249..5e13a614ff0 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableLatenciesImpl.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableLatenciesImpl.java @@ -47,6 +47,9 @@ public class MetricsTableLatenciesImpl extends BaseSourceImpl implements Metrics final MetricHistogram deleteBatchTimeHisto; final MetricHistogram scanTimeHisto; final MetricHistogram scanSizeHisto; + final MetricHistogram checkAndDeleteTimeHisto; + final MetricHistogram checkAndPutTimeHisto; + final MetricHistogram checkAndMutateTimeHisto; TableHistograms(DynamicMetricsRegistry registry, TableName tn) { getTimeHisto = registry.newTimeHistogram(qualifyMetricsName(tn, GET_TIME)); @@ -60,6 +63,12 @@ public class MetricsTableLatenciesImpl extends BaseSourceImpl implements Metrics qualifyMetricsName(tn, DELETE_BATCH_TIME)); scanTimeHisto = registry.newTimeHistogram(qualifyMetricsName(tn, SCAN_TIME)); scanSizeHisto = registry.newSizeHistogram(qualifyMetricsName(tn, SCAN_SIZE)); + checkAndDeleteTimeHisto = + registry.newTimeHistogram(qualifyMetricsName(tn, CHECK_AND_DELETE_TIME)); + checkAndPutTimeHisto = + registry.newTimeHistogram(qualifyMetricsName(tn, CHECK_AND_PUT_TIME)); + checkAndMutateTimeHisto = + registry.newTimeHistogram(qualifyMetricsName(tn, CHECK_AND_MUTATE_TIME)); } public void updatePut(long time) { @@ -97,6 +106,18 @@ public class MetricsTableLatenciesImpl extends BaseSourceImpl implements Metrics public void updateScanTime(long t) { scanTimeHisto.add(t); } + + public void updateCheckAndDeleteTime(long t) { + checkAndDeleteTimeHisto.add(t); + } + + public void updateCheckAndPutTime(long t) { + checkAndPutTimeHisto.add(t); + } + + public void updateCheckAndMutateTime(long t) { + checkAndMutateTimeHisto.add(t); + } } @VisibleForTesting @@ -174,6 +195,21 @@ public class MetricsTableLatenciesImpl extends BaseSourceImpl implements Metrics getOrCreateTableHistogram(tableName).updateScanTime(t); } + @Override + public void updateCheckAndDelete(String tableName, long time) { + getOrCreateTableHistogram(tableName).updateCheckAndDeleteTime(time); + } + + @Override + public void updateCheckAndPut(String tableName, long time) { + getOrCreateTableHistogram(tableName).updateCheckAndPutTime(time); + } + + @Override + public void updateCheckAndMutate(String tableName, long time) { + getOrCreateTableHistogram(tableName).updateCheckAndMutateTime(time); + } + @Override public void getMetrics(MetricsCollector metricsCollector, boolean all) { MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName); 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 715da6c47bd..e37a2722c9f 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 @@ -145,15 +145,24 @@ public class MetricsRegionServer { serverSource.updateDeleteBatch(t); } - public void updateCheckAndDelete(long t) { + public void updateCheckAndDelete(TableName tn, long t) { + if (tableMetrics != null && tn != null) { + tableMetrics.updateCheckAndDelete(tn, t); + } serverSource.updateCheckAndDelete(t); } - public void updateCheckAndPut(long t) { + public void updateCheckAndPut(TableName tn, long t) { + if (tableMetrics != null && tn != null) { + tableMetrics.updateCheckAndPut(tn, t); + } serverSource.updateCheckAndPut(t); } - public void updateCheckAndMutate(long t) { + public void updateCheckAndMutate(TableName tn, long t) { + if (tableMetrics != null && tn != null) { + tableMetrics.updateCheckAndMutate(tn, t); + } serverSource.updateCheckAndMutate(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 a59f5e609b1..d7ba9fc8a28 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 @@ -3076,15 +3076,18 @@ public class RSRpcServices implements HBaseRPCErrorHandler, MetricsRegionServer metricsRegionServer = regionServer.getMetrics(); if (metricsRegionServer != null) { long after = EnvironmentEdgeManager.currentTime(); - metricsRegionServer.updateCheckAndMutate(after - before); + metricsRegionServer.updateCheckAndMutate( + region.getRegionInfo().getTable(), after - before); MutationType type = mutation.getMutateType(); switch (type) { case PUT: - metricsRegionServer.updateCheckAndPut(after - before); + metricsRegionServer.updateCheckAndPut( + region.getRegionInfo().getTable(), after - before); break; case DELETE: - metricsRegionServer.updateCheckAndDelete(after - before); + metricsRegionServer.updateCheckAndDelete( + region.getRegionInfo().getTable(), after - before); break; default: break; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerTableMetrics.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerTableMetrics.java index ec6c0493bb7..812ae45e884 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerTableMetrics.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerTableMetrics.java @@ -65,6 +65,18 @@ public class RegionServerTableMetrics { latencies.updateDeleteBatch(table.getNameAsString(), time); } + public void updateCheckAndDelete(TableName table, long time) { + latencies.updateCheckAndDelete(table.getNameAsString(), time); + } + + public void updateCheckAndPut(TableName table, long time) { + latencies.updateCheckAndPut(table.getNameAsString(), time); + } + + public void updateCheckAndMutate(TableName table, long time) { + latencies.updateCheckAndMutate(table.getNameAsString(), time); + } + public void updateScanTime(TableName table, long time) { latencies.updateScanTime(table.getNameAsString(), time); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java index 574b1e4130c..e56eb0f20aa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java @@ -151,9 +151,9 @@ public class TestMetricsRegionServer { for (int i=0; i < 17; i ++) { rsm.updatePut(null, 17); rsm.updateDelete(null, 17); - rsm.updateCheckAndDelete(17); - rsm.updateCheckAndPut(17); - rsm.updateCheckAndMutate(17); + rsm.updateCheckAndDelete(null, 17); + rsm.updateCheckAndPut(null, 17); + rsm.updateCheckAndMutate(null, 17); } HELPER.assertCounter("appendNumOps", 24, serverSource); @@ -174,17 +174,6 @@ public class TestMetricsRegionServer { HELPER.assertCounter("slowPutCount", 16, serverSource); } - String FLUSH_TIME = "flushTime"; - String FLUSH_TIME_DESC = "Histogram for the time in millis for memstore flush"; - String FLUSH_MEMSTORE_SIZE = "flushMemstoreSize"; - String FLUSH_MEMSTORE_SIZE_DESC = "Histogram for number of bytes in the memstore for a flush"; - String FLUSH_FILE_SIZE = "flushFileSize"; - String FLUSH_FILE_SIZE_DESC = "Histogram for number of bytes in the resulting file for a flush"; - String FLUSHED_OUTPUT_BYTES = "flushedOutputBytes"; - String FLUSHED_OUTPUT_BYTES_DESC = "Total number of bytes written from flush"; - String FLUSHED_MEMSTORE_BYTES = "flushedMemstoreBytes"; - String FLUSHED_MEMSTORE_BYTES_DESC = "Total number of bytes of cells in memstore from flush"; - @Test public void testFlush() { rsm.updateFlush(null, 1, 2, 3);