HBASE-17565 StochasticLoadBalancer may incorrectly skip balancing due to skewed multiplier sum

This commit is contained in:
tedyu 2017-02-07 06:26:12 -08:00
parent 0a0aef345a
commit 5a0020e867
5 changed files with 15 additions and 5 deletions

View File

@ -283,6 +283,10 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
if (multiplier <= 0) { if (multiplier <= 0) {
continue; continue;
} }
if (!c.isNeeded()) {
LOG.debug(c.getClass().getName() + " indicated that its cost should not be considered");
continue;
}
sumMultiplier += multiplier; sumMultiplier += multiplier;
total += c.cost() * multiplier; total += c.cost() * multiplier;
} }
@ -926,9 +930,11 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
protected Cluster cluster; protected Cluster cluster;
CostFunction(Configuration c) { CostFunction(Configuration c) {
} }
boolean isNeeded() {
return true;
}
float getMultiplier() { float getMultiplier() {
return multiplier; return multiplier;
} }
@ -1433,6 +1439,11 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
return costPerGroup(primariesOfRegions); return costPerGroup(primariesOfRegions);
} }
@Override
boolean isNeeded() {
return cluster.hasRegionReplicas;
}
@Override @Override
double cost() { double cost() {
if (maxCost <= 0) { if (maxCost <= 0) {

View File

@ -84,7 +84,6 @@ public class TestRegionRebalancing {
public void before() throws Exception { public void before() throws Exception {
UTIL.getConfiguration().set("hbase.master.loadbalancer.class", this.balancerName); UTIL.getConfiguration().set("hbase.master.loadbalancer.class", this.balancerName);
// set minCostNeedBalance to 0, make sure balancer run // set minCostNeedBalance to 0, make sure balancer run
UTIL.getConfiguration().setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f);
UTIL.startMiniCluster(1); UTIL.startMiniCluster(1);
this.desc = new HTableDescriptor(TableName.valueOf("test")); this.desc = new HTableDescriptor(TableName.valueOf("test"));
this.desc.addFamily(new HColumnDescriptor(FAMILY_NAME)); this.desc.addFamily(new HColumnDescriptor(FAMILY_NAME));

View File

@ -71,7 +71,6 @@ public class BalancerTestBase {
conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 0.75f); conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 0.75f);
conf.setFloat("hbase.regions.slop", 0.0f); conf.setFloat("hbase.regions.slop", 0.0f);
conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0); conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0);
conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f);
loadBalancer = new StochasticLoadBalancer(); loadBalancer = new StochasticLoadBalancer();
loadBalancer.setConf(conf); loadBalancer.setConf(conf);
} }
@ -129,6 +128,9 @@ public class BalancerTestBase {
new int[]{0, 0, 0, 7}, new int[]{0, 0, 0, 7},
// 5 node // 5 node
new int[]{1, 1, 1, 1, 4}, 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 // more nodes
new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 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}, new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 10},

View File

@ -104,7 +104,6 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
assertNull(plans); assertNull(plans);
} }
// reset config // reset config
conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f);
loadBalancer.setConf(conf); loadBalancer.setConf(conf);
} }

View File

@ -42,7 +42,6 @@ public class TestStochasticLoadBalancer2 extends BalancerTestBase {
@After @After
public void after() { public void after() {
// reset config to make sure balancer run // reset config to make sure balancer run
conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f);
loadBalancer.setConf(conf); loadBalancer.setConf(conf);
} }