From 6c18d9735701b94dad7396d5ce1e2702ba1a6d48 Mon Sep 17 00:00:00 2001 From: tedyu Date: Sun, 22 Jul 2018 20:51:58 -0700 Subject: [PATCH] HBASE-20917 MetaTableMetrics#stop references uninitialized requestsMap for non-meta region with addendum (cherry picked from commit 654480326b9a8a5fa9d9314d1cfced6a45cfa941) (cherry picked from commit 3787c729530ab7cf7f759decf2cbe961ff95f497) --- .../hbase/coprocessor/MetaTableMetrics.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MetaTableMetrics.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MetaTableMetrics.java index 9bf35c0fb98..3bb47ae062c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MetaTableMetrics.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MetaTableMetrics.java @@ -197,9 +197,8 @@ public class MetaTableMetrics implements RegionCoprocessor { } private boolean isMetaTableOp(ObserverContext e) { - return TableName.META_TABLE_NAME.toString() - .equals(new String(e.getEnvironment().getRegionInfo().getTable().getName(), - StandardCharsets.UTF_8)); + return TableName.META_TABLE_NAME + .equals(e.getEnvironment().getRegionInfo().getTable()); } private void clientMetricRegisterAndMark(ObserverContext e) { @@ -309,9 +308,8 @@ public class MetaTableMetrics implements RegionCoprocessor { public void start(CoprocessorEnvironment env) throws IOException { if (env instanceof RegionCoprocessorEnvironment && ((RegionCoprocessorEnvironment) env).getRegionInfo().getTable() != null - && ((RegionCoprocessorEnvironment) env).getRegionInfo().getTable().getName() != null - && new String(((RegionCoprocessorEnvironment) env).getRegionInfo().getTable().getName(), - StandardCharsets.UTF_8).equals(TableName.META_TABLE_NAME.toString())) { + && ((RegionCoprocessorEnvironment) env).getRegionInfo().getTable() + .equals(TableName.META_TABLE_NAME)) { regionCoprocessorEnv = (RegionCoprocessorEnvironment) env; observer = new ExampleRegionObserverMeta(); requestsMap = new ConcurrentHashMap<>(); @@ -324,11 +322,13 @@ public class MetaTableMetrics implements RegionCoprocessor { } @Override - public void stop(CoprocessorEnvironment e) throws IOException { + public void stop(CoprocessorEnvironment env) throws IOException { // since meta region can move around, clear stale metrics when stop. - for (String meterName : requestsMap.keySet()) { - MetricRegistry registry = regionCoprocessorEnv.getMetricRegistryForRegionServer(); - registry.remove(meterName); + if (requestsMap != null) { + for (String meterName : requestsMap.keySet()) { + MetricRegistry registry = regionCoprocessorEnv.getMetricRegistryForRegionServer(); + registry.remove(meterName); + } } }