HBASE-20917 MetaTableMetrics#stop references uninitialized requestsMap for non-meta region

with addendum

(cherry picked from commit 654480326b)
(cherry picked from commit 3787c72953)
This commit is contained in:
tedyu 2018-07-22 20:51:58 -07:00 committed by Sean Busbey
parent d89e5270aa
commit 6c18d97357
1 changed files with 10 additions and 10 deletions

View File

@ -197,9 +197,8 @@ public class MetaTableMetrics implements RegionCoprocessor {
}
private boolean isMetaTableOp(ObserverContext<RegionCoprocessorEnvironment> 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<RegionCoprocessorEnvironment> 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);
}
}
}