HBASE-26308 Sum of multiplier of cost functions is not populated prop… (#3782)
Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Huaxiang Sun <huaxiangsun@apache.org>
This commit is contained in:
parent
d483e105c8
commit
d23a5b5aac
|
@ -149,8 +149,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
|
|
||||||
private List<CandidateGenerator> candidateGenerators;
|
private List<CandidateGenerator> candidateGenerators;
|
||||||
private List<CostFunction> costFunctions; // FindBugs: Wants this protected; IS2_INCONSISTENT_SYNC
|
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;
|
||||||
private float sumMultiplier = 1.0f;
|
|
||||||
// to save and report costs to JMX
|
// to save and report costs to JMX
|
||||||
private double curOverallCost = 0d;
|
private double curOverallCost = 0d;
|
||||||
private double[] tempFunctionCosts;
|
private double[] tempFunctionCosts;
|
||||||
|
@ -240,8 +239,9 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
LOG.info(
|
LOG.info(
|
||||||
"Loaded config; maxSteps=" + maxSteps + ", runMaxSteps=" + runMaxSteps +
|
"Loaded config; maxSteps=" + maxSteps + ", runMaxSteps=" + runMaxSteps +
|
||||||
", stepsPerRegion=" + stepsPerRegion +
|
", stepsPerRegion=" + stepsPerRegion +
|
||||||
", maxRunningTime=" + maxRunningTime + ", isByTable=" + isByTable
|
", maxRunningTime=" + maxRunningTime + ", isByTable=" + isByTable +
|
||||||
+ ", CostFunctions=" + Arrays.toString(getCostFunctionNames()) + " etc.");
|
", CostFunctions=" + Arrays.toString(getCostFunctionNames()) +
|
||||||
|
" , sum of multiplier of cost functions = " + sumMultiplier + " etc.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadCustomCostFunctions(Configuration conf) {
|
private void loadCustomCostFunctions(Configuration conf) {
|
||||||
|
@ -334,31 +334,24 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (areSomeRegionReplicasColocated(cluster)) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idleRegionServerExist(cluster)){
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sumMultiplier = 0.0f;
|
|
||||||
double total = 0.0;
|
double total = 0.0;
|
||||||
for (CostFunction c : costFunctions) {
|
for (CostFunction c : costFunctions) {
|
||||||
float multiplier = c.getMultiplier();
|
|
||||||
double cost = c.cost();
|
|
||||||
if (!c.isNeeded()) {
|
if (!c.isNeeded()) {
|
||||||
LOG.trace("{} not needed", c.getClass().getSimpleName());
|
LOG.trace("{} not needed", c.getClass().getSimpleName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
total += cost * multiplier;
|
total += c.cost() * c.getMultiplier();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean balanced = (total / sumMultiplier < minCostNeedBalance);
|
boolean balanced = (total / sumMultiplier < minCostNeedBalance);
|
||||||
|
@ -434,6 +427,17 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
long startTime = EnvironmentEdgeManager.currentTime();
|
||||||
|
|
||||||
initCosts(cluster);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
if (!needsBalance(tableName, cluster)) {
|
if (!needsBalance(tableName, cluster)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -605,8 +609,8 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
builder.append(", ");
|
builder.append(", ");
|
||||||
double cost = c.cost();
|
double cost = c.cost();
|
||||||
builder.append("imbalance=" + cost);
|
builder.append("imbalance=" + cost);
|
||||||
if (cost < minCostNeedBalance) {
|
if (cost >= minCostNeedBalance) {
|
||||||
builder.append(", balanced");
|
builder.append(", need balance");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
builder.append("not needed");
|
builder.append("not needed");
|
||||||
|
@ -1229,7 +1233,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to be used for the subset of RegionLoad costs that should be treated as rates.
|
* Class to be used for the subset of RegionLoad csts that should be treated as rates.
|
||||||
* We do not compare about the actual rate in requests per second but rather the rate relative
|
* We do not compare about the actual rate in requests per second but rather the rate relative
|
||||||
* to the rest of the regions.
|
* to the rest of the regions.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue