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

This commit is contained in:
tedyu 2018-07-23 10:04:10 -07:00
parent 9db4a4059a
commit a7fe71da88
1 changed files with 8 additions and 7 deletions

View File

@ -294,9 +294,8 @@ public class MetaTableMetrics extends BaseRegionObserver {
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;
requestsMap = new ConcurrentHashMap<>();
clientMetricsLossyCounting = new LossyCounting();
@ -306,11 +305,13 @@ public class MetaTableMetrics extends BaseRegionObserver {
}
@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);
}
}
}