From 17bdf9fa8cbe920578c09c38960dd0450746fe5c Mon Sep 17 00:00:00 2001 From: Enis Soztutar Date: Wed, 16 Sep 2015 17:29:37 -0700 Subject: [PATCH] HBASE-14082 Add replica id to JMX metrics names (Lei Chen) --- .../regionserver/MetricsRegionSource.java | 2 ++ .../regionserver/MetricsRegionWrapper.java | 5 +++ .../regionserver/MetricsRegionSourceImpl.java | 3 ++ .../TestMetricsRegionSourceImpl.java | 8 +++++ .../MetricsRegionWrapperImpl.java | 8 +++++ .../MetricsRegionWrapperStub.java | 23 +++++++++++++ .../hbase/regionserver/TestMetricsRegion.java | 32 +++++++++++++++++-- 7 files changed, 78 insertions(+), 3 deletions(-) diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSource.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSource.java index 8abbb1f2d263..874be3192734 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSource.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSource.java @@ -37,6 +37,8 @@ public interface MetricsRegionSource extends Comparable { "Number of files that were input for finished, successful or aborted, compactions"; String COPROCESSOR_EXECUTION_STATISTICS = "coprocessorExecutionStatistics"; String COPROCESSOR_EXECUTION_STATISTICS_DESC = "Statistics for coprocessor execution times"; + String REPLICA_ID = "replicaid"; + String REPLICA_ID_DESC = "The replica ID of a region. 0 is primary, otherwise is secondary"; /** * Close the region's metrics as this region is closing. diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java index cfc0b66a3525..46bc37acd6f5 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java @@ -90,4 +90,9 @@ public interface MetricsRegionWrapper { * Get the time spent by coprocessors in this region. */ Map getCoprocessorExecutionStatistics(); + + /** + * Get the replica id of this region. + */ + int getReplicaId(); } diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java index 0ecf2b2a5743..bd123b9a0b1c 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java @@ -242,6 +242,9 @@ void snapshot(MetricsRecordBuilder mrb, boolean ignored) { regionNamePrefix + MetricsRegionServerSource.WRITE_REQUEST_COUNT, MetricsRegionServerSource.WRITE_REQUEST_COUNT_DESC), this.regionWrapper.getWriteRequestCount()); + mrb.addCounter(Interns.info(regionNamePrefix + MetricsRegionSource.REPLICA_ID, + MetricsRegionSource.REPLICA_ID_DESC), + this.regionWrapper.getReplicaId()); for (Map.Entry entry : this.regionWrapper .getCoprocessorExecutionStatistics() diff --git a/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java b/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java index 9d60a8ff2c8d..3242b67cfda1 100644 --- a/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java +++ b/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java @@ -133,5 +133,13 @@ public int getRegionHashCode() { public Map getCoprocessorExecutionStatistics() { return null; } + + /** + * Always return 0 for testing + */ + @Override + public int getReplicaId() { + return 0; + } } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperImpl.java index 78df787b918f..3f1da850cd57 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperImpl.java @@ -174,4 +174,12 @@ public Map getCoprocessorExecutionStatistics() { return coprocessorTimes; } + /** + * Get the replica id of this region. + */ + @Override + public int getReplicaId() { + return region.getRegionInfo().getReplicaId(); + } + } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperStub.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperStub.java index 94ac35610b5a..2b1a9b7b4cf6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperStub.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapperStub.java @@ -24,6 +24,21 @@ import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; public class MetricsRegionWrapperStub implements MetricsRegionWrapper { + int replicaid = 0; + + /** + * Replica ID set to 0 + */ + public MetricsRegionWrapperStub() { + this.replicaid = 0; + } + + /** + * Pass in replica ID + */ + public MetricsRegionWrapperStub(int replicaid) { + this.replicaid = replicaid; + } @Override public String getTableName() { @@ -94,4 +109,12 @@ public int getRegionHashCode() { public Map getCoprocessorExecutionStatistics() { return new HashMap(); } + + /** + * Get the replica id of this region. + */ + @Override + public int getReplicaId() { + return replicaid; + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegion.java index ddaee3dcb3a0..e7398905cd6c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegion.java @@ -36,9 +36,35 @@ public void testRegionWrapperMetrics() { MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub()); MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource(); - HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 101, agg); - HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 102, agg); - HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 103, agg); + HELPER.assertGauge( + "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", + 101, agg); + HELPER.assertGauge( + "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", + 102, agg); + HELPER.assertGauge( + "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", + 103, agg); + HELPER.assertCounter( + "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", + 0, agg); + mr.close(); + + // test region with replica id > 0 + mr = new MetricsRegion(new MetricsRegionWrapperStub(1)); + agg = mr.getSource().getAggregateSource(); + HELPER.assertGauge( + "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", + 101, agg); + HELPER.assertGauge( + "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", + 102, agg); + HELPER.assertGauge( + "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", + 103, agg); + HELPER.assertCounter( + "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", + 1, agg); mr.close(); } }