diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java index 36d37099262..8872da6c7b2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java @@ -283,6 +283,10 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { if (multiplier <= 0) { continue; } + if (!c.isNeeded()) { + LOG.debug(c.getClass().getName() + " indicated that its cost should not be considered"); + continue; + } sumMultiplier += multiplier; total += c.cost() * multiplier; } @@ -926,9 +930,11 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { protected Cluster cluster; CostFunction(Configuration c) { - } + boolean isNeeded() { + return true; + } float getMultiplier() { return multiplier; } @@ -1433,6 +1439,11 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { return costPerGroup(primariesOfRegions); } + @Override + boolean isNeeded() { + return cluster.hasRegionReplicas; + } + @Override double cost() { if (maxCost <= 0) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java index e4890e63e7c..90e74f91ba0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java @@ -84,7 +84,6 @@ public class TestRegionRebalancing { public void before() throws Exception { UTIL.getConfiguration().set("hbase.master.loadbalancer.class", this.balancerName); // set minCostNeedBalance to 0, make sure balancer run - UTIL.getConfiguration().setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f); UTIL.startMiniCluster(1); this.desc = new HTableDescriptor(TableName.valueOf("test")); this.desc.addFamily(new HColumnDescriptor(FAMILY_NAME)); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java index 5746e3f7001..5bd6606f20b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java @@ -71,7 +71,6 @@ public class BalancerTestBase { conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 0.75f); conf.setFloat("hbase.regions.slop", 0.0f); conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0); - conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f); loadBalancer = new StochasticLoadBalancer(); loadBalancer.setConf(conf); } @@ -129,6 +128,9 @@ public class BalancerTestBase { new int[]{0, 0, 0, 7}, // 5 node new int[]{1, 1, 1, 1, 4}, + // 6 nodes + new int[]{1500, 500, 500, 500, 10, 0}, + new int[]{1500, 500, 500, 500, 500, 0}, // more nodes new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 10}, diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java index 3d975b8a179..8e3ec7c5080 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java @@ -104,7 +104,6 @@ public class TestStochasticLoadBalancer extends BalancerTestBase { assertNull(plans); } // reset config - conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f); loadBalancer.setConf(conf); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer2.java index 62ad8a3722d..aafefca6e10 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer2.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer2.java @@ -42,7 +42,6 @@ public class TestStochasticLoadBalancer2 extends BalancerTestBase { @After public void after() { // reset config to make sure balancer run - conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f); loadBalancer.setConf(conf); }