diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 9e69eae..6ca99a9 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -85,6 +85,8 @@ import org.apache.hadoop.hbase.ipc.HBaseRPC; import org.apache.hadoop.hbase.ipc.HBaseServer; import org.apache.hadoop.hbase.ipc.ProtocolSignature; import org.apache.hadoop.hbase.ipc.RpcServer; +import org.apache.hadoop.hbase.master.balancer.BalancerChore; +import org.apache.hadoop.hbase.master.balancer.ClusterStatusChore; import org.apache.hadoop.hbase.master.balancer.LoadBalancerFactory; import org.apache.hadoop.hbase.master.cleaner.HFileCleaner; import org.apache.hadoop.hbase.master.cleaner.LogCleaner; @@ -284,6 +286,7 @@ Server { private LoadBalancer balancer; private Thread balancerChore; + private Thread clusterStatusChore; private CatalogJanitor catalogJanitorChore; private LogCleaner logCleaner; @@ -309,6 +312,7 @@ Server { private final boolean masterCheckCompression; private SpanReceiverHost spanReceiverHost; + /** * Initializes the HMaster. The steps are as follows: *
@@ -700,6 +704,7 @@ Server {
// Start balancer and meta catalog janitor after meta and regions have
// been assigned.
status.setStatus("Starting balancer and catalog janitor");
+ this.clusterStatusChore = getAndStartClusterStatusChore(this);
this.balancerChore = getAndStartBalancerChore(this);
this.catalogJanitorChore = new CatalogJanitor(this, this);
startCatalogJanitorChore();
@@ -1083,17 +1088,17 @@ Server {
if (this.executorService != null) this.executorService.shutdown();
}
+ private static Thread getAndStartClusterStatusChore(HMaster master) {
+ if (master == null || master.balancer == null) {
+ return null;
+ }
+ Chore chore = new ClusterStatusChore(master, master.balancer);
+ return Threads.setDaemonThreadRunning(chore.getThread());
+ }
+
private static Thread getAndStartBalancerChore(final HMaster master) {
- String name = master.getServerName() + "-BalancerChore";
- int balancerPeriod =
- master.getConfiguration().getInt("hbase.balancer.period", 300000);
// Start up the load balancer chore
- Chore chore = new Chore(name, balancerPeriod, master) {
- @Override
- protected void chore() {
- master.balance();
- }
- };
+ Chore chore = new BalancerChore(master);
return Threads.setDaemonThreadRunning(chore.getThread());
}
@@ -1101,6 +1106,9 @@ Server {
if (this.balancerChore != null) {
this.balancerChore.interrupt();
}
+ if (this.clusterStatusChore != null) {
+ this.clusterStatusChore.interrupt();
+ }
if (this.catalogJanitorChore != null) {
this.catalogJanitorChore.interrupt();
}
diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerChore.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerChore.java
new file mode 100644
index 0000000..b662af5
--- /dev/null
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerChore.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.balancer;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.Chore;
+import org.apache.hadoop.hbase.master.HMaster;
+
+/**
+ * Chore that will call HMaster.balance{@link org.apache.hadoop.hbase.master.HMaster#balance()} when
+ * needed.
+ */
+@InterfaceAudience.Private
+public class BalancerChore extends Chore {
+
+ private final HMaster master;
+
+ public BalancerChore(HMaster master) {
+ super(master.getServerName() + "-BalancerChore",
+ master.getConfiguration().getInt("hbase.balancer.period", 300000),
+ master);
+ this.master = master;
+ }
+
+ @Override
+ protected void chore() {
+ master.balance();
+ }
+}
diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/ClusterStatusChore.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/ClusterStatusChore.java
new file mode 100644
index 0000000..23f7843
--- /dev/null
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/ClusterStatusChore.java
@@ -0,0 +1,47 @@
+/**
+ * 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.balancer;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.Chore;
+import org.apache.hadoop.hbase.master.HMaster;
+import org.apache.hadoop.hbase.master.LoadBalancer;
+
+/**
+ * Chore that will feed the balancer the cluster status.
+ */
+@InterfaceAudience.Private
+public class ClusterStatusChore extends Chore {
+
+ private final HMaster master;
+ private final LoadBalancer balancer;
+
+ public ClusterStatusChore(HMaster master, LoadBalancer balancer) {
+ super(master.getServerName() + "-ClusterStatusChore",
+ master.getConfiguration().getInt("hbase.balancer.statusPeriod", 60000),
+ master);
+ this.master = master;
+ this.balancer = balancer;
+ }
+
+ @Override
+ protected void chore() {
+ balancer.setClusterStatus(master.getClusterStatus());
+ }
+}
diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
index af5ddf2..370c9f3 100644
--- hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
@@ -104,17 +104,19 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
"hbase.master.balancer.stochastic.stepsPerRegion";
private static final String MAX_STEPS_KEY = "hbase.master.balancer.stochastic.maxSteps";
private static final String MAX_MOVES_KEY = "hbase.master.balancer.stochastic.maxMoveRegions";
+ private static final String KEEP_REGION_LOADS = "hbase.master.balancer.stochastic.numRegionLoadsToRemember";
private static final Random RANDOM = new Random(System.currentTimeMillis());
private static final Log LOG = LogFactory.getLog(StochasticLoadBalancer.class);
private final RegionLocationFinder regionFinder = new RegionLocationFinder();
private ClusterStatus clusterStatus = null;
- private Map