diff --git conf/hbase-site.xml conf/hbase-site.xml
index c516ac7..6093139 100644
--- conf/hbase-site.xml
+++ conf/hbase-site.xml
@@ -21,4 +21,18 @@
*/
-->
+
+ hbase.rootdir
+ file:///Users/jgub/repos/hbase
+
+
+
+ hbase.coprocessor.master.classes
+ org.apache.hadoop.hbase.security.access.AccessController
+
+
+ hbase.coprocessor.region.classes
+ org.apache.hadoop.hbase.security.token.TokenProvider,
+ org.apache.hadoop.hbase.security.access.AccessController
+
diff --git hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSource.java hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSource.java
new file mode 100644
index 0000000..fbcc974
--- /dev/null
+++ hbase-hadoop-compat/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 showing HBase regions' states.";
+
+ public void updateRegionState(String name, String state);
+
+ public void deleteRegionState(String name);
+}
diff --git hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSourceImpl.java hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSourceImpl.java
new file mode 100644
index 0000000..54bd12c
--- /dev/null
+++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsRegionStatesSourceImpl.java
@@ -0,0 +1,77 @@
+/**
+ * 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.classification.InterfaceAudience;
+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;
+
+
+@InterfaceAudience.Private
+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.intern(), state.intern());
+ }
+
+ @Override
+ public void deleteRegionState(String 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) {
+ MetricsRecordBuilder mrb = collector.addRecord("RegionState");
+
+ for (String key : regionStates.keySet()) {
+ mrb.tag(Interns.info(key, key), regionStates.get(key));
+ }
+ }
+}
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-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/TestMetricsRegionStatesSourceImpl.java hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/TestMetricsRegionStatesSourceImpl.java
new file mode 100644
index 0000000..ca48d64
--- /dev/null
+++ hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/TestMetricsRegionStatesSourceImpl.java
@@ -0,0 +1,60 @@
+/**
+ * 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.CompatibilityFactory;
+import org.apache.hadoop.hbase.test.MetricsAssertHelper;
+import org.apache.hadoop.hbase.testclassification.MetricsTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Test for TestMetricsRegionStatesSourceImpl
+ */
+@Category({MetricsTests.class, SmallTests.class})
+public class TestMetricsRegionStatesSourceImpl {
+
+ private static MetricsRegionStatesSourceImpl metricsRegionStatesSource;
+ public static MetricsAssertHelper HELPER =
+ CompatibilityFactory.getInstance(MetricsAssertHelper.class);
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ metricsRegionStatesSource = new MetricsRegionStatesSourceImpl();
+ metricsRegionStatesSource.init();
+ }
+
+ @Test
+ public void testRegionStateChange() throws Exception {
+ String name = "hbase:mytable-asdf";
+ String state = "OPEN";
+
+ metricsRegionStatesSource.updateRegionState(name, state);
+ HELPER.assertTag(name, state, metricsRegionStatesSource);
+
+ String state2 = "OPEN";
+ metricsRegionStatesSource.updateRegionState(name, state2);
+ HELPER.assertTag(name, state2, metricsRegionStatesSource);
+
+ metricsRegionStatesSource.deleteRegionState(name);
+ HELPER.assertTag(name, null, metricsRegionStatesSource);
+ }
+}
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..94f0878
--- /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 name, String state) {
+ regionStatesSource.updateRegionState(name, state);
+ }
+
+ public void deleteRegionState(String name) {
+ regionStatesSource.deleteRegionState(name);
+ }
+}
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..a1bf55e 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,8 @@ public class RegionStates {
String encodedName = hri.getEncodedName();
TableName table = hri.getTable();
RegionState oldState = regionStates.put(encodedName, regionState);
+ String metricName = (table.getNameAsString() + "-" + encodedName).intern();
+ metricsRegionStates.updateRegionState(metricName, regionState.toString());
Map map = regionStatesTableIndex.get(table);
if (map == null) {
map = new HashMap<>();
@@ -794,6 +799,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);