diff --git hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.master.MetricsRegionStatesSource hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.master.MetricsRegionStatesSource new file mode 100644 index 0000000..e40a15b --- /dev/null +++ hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.master.MetricsRegionStatesSource @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +org.apache.hadoop.hbase.master.MetricsRegionStatesSourceImpl diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index 69ebd97..e04825e 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -113,6 +113,7 @@ public class AssignmentManager { private final MetricsAssignmentManager metricsAssignmentManager; + private AtomicInteger numRegionsOpened = new AtomicInteger(0); final private KeyLocker locker = new KeyLocker<>(); diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStates.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStates.java new file mode 100644 index 0000000..0d68118 --- /dev/null +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStates.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.master; + +import org.apache.hadoop.hbase.CompatibilitySingletonFactory; + +public class MetricsRegionStates { + + private final MetricsRegionStatesSource regionStatesSource; + + public MetricsRegionStates() { + regionStatesSource = CompatibilitySingletonFactory.getInstance( + MetricsRegionStatesSource.class); + } + + public MetricsRegionStatesSource getMetricsProcSource() { + return regionStatesSource; + } + + public void updateRegionState(String encodedName, String state) { + regionStatesSource.updateRegionState(encodedName, state); + } + + public void deleteRegionState(String encodedName) { + regionStatesSource.deleteRegionState(encodedName); + } +} diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSource.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSource.java new file mode 100644 index 0000000..a2dd5ab --- /dev/null +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSource.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.master; + +public interface MetricsRegionStatesSource { + /** + * The name of the metrics + */ + String METRICS_NAME = "RegionStates"; + + /** + * The context metrics will be under. + */ + String METRICS_CONTEXT = "master"; + + /** + * The name of the metrics context that metrics will be under in jmx + */ + String METRICS_JMX_CONTEXT = "Master,sub=" + METRICS_NAME; + + /** + * Description + */ + String METRICS_DESCRIPTION = "Metrics about HBase regions."; + + public void updateRegionState(String encodedName, String state); + + public void deleteRegionState(String encodedName); +} diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSourceImpl.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSourceImpl.java new file mode 100644 index 0000000..cb64444 --- /dev/null +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSourceImpl.java @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.master; + +import org.apache.hadoop.hbase.metrics.BaseSourceImpl; +import org.apache.hadoop.hbase.metrics.Interns; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsRecordBuilder; + +import java.util.HashMap; +import java.util.Map; + + +public class MetricsRegionStatesSourceImpl extends BaseSourceImpl + implements MetricsRegionStatesSource { + + private Map regionStates; + + public MetricsRegionStatesSourceImpl() { + this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT); + } + + public MetricsRegionStatesSourceImpl(String metricsName, + String metricsDescription, + String metricsContext, String metricsJmxContext) { + super(metricsName, metricsDescription, metricsContext, metricsJmxContext); + } + + public void init() { + regionStates = new HashMap<>(); + } + + @Override + public void updateRegionState(String encodedName, String state) { + regionStates.put(encodedName, state); + } + + @Override + public void deleteRegionState(String encodedName) { + if (regionStates.containsKey(encodedName)) regionStates.remove(encodedName); + } + + /** + * Yes this is a get function that doesn't return anything. Thanks Hadoop for breaking all + * expectations of java programmers. Instead of returning anything Hadoop metrics expects + * getMetrics to push the metrics into the collector. + * + * @param collector the collector + * @param all get all the metrics regardless of when they last changed. + */ + @Override + public void getMetrics(MetricsCollector collector, boolean all) { + super.getMetrics(collector, all); + MetricsRecordBuilder mrb = collector.addRecord("RegionState"); + + for (String key : regionStates.keySet()) { + mrb.tag(Interns.info(key, key), regionStates.get(key)); + } + } +} diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java index dcbf5a4..34c9437 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java @@ -77,6 +77,8 @@ public class RegionStates { } } + private final MetricsRegionStates metricsRegionStates; + /** * Regions currently in transition. */ @@ -165,6 +167,7 @@ public class RegionStates { this.regionStateStore = regionStateStore; this.serverManager = serverManager; this.server = master; + this.metricsRegionStates = new MetricsRegionStates(); } /** @@ -392,6 +395,7 @@ public class RegionStates { String encodedName = hri.getEncodedName(); TableName table = hri.getTable(); RegionState oldState = regionStates.put(encodedName, regionState); + metricsRegionStates.updateRegionState(encodedName, regionState.toString()); Map map = regionStatesTableIndex.get(table); if (map == null) { map = new HashMap<>(); @@ -794,6 +798,7 @@ public class RegionStates { String encodedName = hri.getEncodedName(); regionsInTransition.remove(encodedName); regionStates.remove(encodedName); + metricsRegionStates.deleteRegionState(encodedName); TableName table = hri.getTable(); Map indexMap = regionStatesTableIndex.get(table); indexMap.remove(encodedName);