Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
private List<CandidateGenerator> candidateGenerators;
private List<CostFunction> costFunctions; // FindBugs: Wants this protected; IS2_INCONSISTENT_SYNC
// To save currently configed sum of multiplier. Defaulted at 1 for cases that carry high cost
private float sumMultiplier = 1.0f;
private float sumMultiplier;
// to save and report costs to JMX
private double curOverallCost = 0d;
private double[] tempFunctionCosts;
Expand Down Expand Up @@ -248,8 +248,9 @@ public synchronized void setConf(Configuration conf) {
LOG.info(
"Loaded config; maxSteps=" + maxSteps + ", runMaxSteps=" + runMaxSteps +
", stepsPerRegion=" + stepsPerRegion +
", maxRunningTime=" + maxRunningTime + ", isByTable=" + isByTable
+ ", CostFunctions=" + Arrays.toString(getCostFunctionNames()) + " etc.");
", maxRunningTime=" + maxRunningTime + ", isByTable=" + isByTable +
", CostFunctions=" + Arrays.toString(getCostFunctionNames()) +
" , sum of multiplier of cost functions = " + sumMultiplier + " etc.");
}

private void loadCustomCostFunctions(Configuration conf) {
Expand Down Expand Up @@ -371,31 +372,24 @@ protected boolean needsBalance(TableName tableName, Cluster cluster) {
return false;
}
if (areSomeRegionReplicasColocated(cluster)) {
LOG.info("Running balancer because at least one server hosts replicas of the same region.");
LOG.info("Running balancer because at least one server hosts replicas of the same region." +
" function cost={}", functionCost());
return true;
}

if (idleRegionServerExist(cluster)){
LOG.info("Running balancer because cluster has idle server(s).");
LOG.info("Running balancer because cluster has idle server(s)."+
" function cost={}", functionCost());
return true;
}

sumMultiplier = 0.0f;
double total = 0.0;
for (CostFunction c : costFunctions) {
float multiplier = c.getMultiplier();
double cost = c.cost();
if (!c.isNeeded()) {
LOG.trace("{} not needed", c.getClass().getSimpleName());
continue;
}
total += cost * multiplier;
sumMultiplier += multiplier;
}
if (sumMultiplier <= 0) {
LOG.error("At least one cost function needs a multiplier > 0. For example, set "
+ "hbase.master.balancer.stochastic.regionCountCost to a positive value or default");
return false;
total += c.cost() * c.getMultiplier();
}

boolean balanced = (total / sumMultiplier < minCostNeedBalance);
Expand Down Expand Up @@ -471,6 +465,17 @@ public synchronized List<RegionPlan> balanceTable(TableName tableName, Map<Serve
long startTime = EnvironmentEdgeManager.currentTime();

initCosts(cluster);
sumMultiplier = 0;
for (CostFunction c : costFunctions) {
if(c.isNeeded()) {
sumMultiplier += c.getMultiplier();
}
}
if (sumMultiplier <= 0) {
LOG.error("At least one cost function needs a multiplier > 0. For example, set "
+ "hbase.master.balancer.stochastic.regionCountCost to a positive value or default");
return null;
}

double currentCost = computeCost(cluster, Double.MAX_VALUE);
curOverallCost = currentCost;
Expand Down Expand Up @@ -642,8 +647,8 @@ private String functionCost() {
builder.append(", ");
double cost = c.cost();
builder.append("imbalance=" + cost);
if (cost < minCostNeedBalance) {
builder.append(", balanced");
if (cost >= minCostNeedBalance) {
builder.append(", need balance");
}
} else {
builder.append("not needed");
Expand Down