Skip to content

Commit 4a38b00

Browse files
HubSpot Backport: HBASE-26308 Sum of multiplier of cost functions is not populated properly when we have a shortcut for trigger
1 parent 814065d commit 4a38b00

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
152152
private List<CandidateGenerator> candidateGenerators;
153153
private List<CostFunction> costFunctions; // FindBugs: Wants this protected; IS2_INCONSISTENT_SYNC
154154
// To save currently configed sum of multiplier. Defaulted at 1 for cases that carry high cost
155-
private float sumMultiplier = 1.0f;
155+
private float sumMultiplier;
156156
// to save and report costs to JMX
157157
private double curOverallCost = 0d;
158158
private double[] tempFunctionCosts;
@@ -248,8 +248,9 @@ public synchronized void setConf(Configuration conf) {
248248
LOG.info(
249249
"Loaded config; maxSteps=" + maxSteps + ", runMaxSteps=" + runMaxSteps +
250250
", stepsPerRegion=" + stepsPerRegion +
251-
", maxRunningTime=" + maxRunningTime + ", isByTable=" + isByTable
252-
+ ", CostFunctions=" + Arrays.toString(getCostFunctionNames()) + " etc.");
251+
", maxRunningTime=" + maxRunningTime + ", isByTable=" + isByTable +
252+
", CostFunctions=" + Arrays.toString(getCostFunctionNames()) +
253+
" , sum of multiplier of cost functions = " + sumMultiplier + " etc.");
253254
}
254255

255256
private void loadCustomCostFunctions(Configuration conf) {
@@ -371,31 +372,24 @@ protected boolean needsBalance(TableName tableName, Cluster cluster) {
371372
return false;
372373
}
373374
if (areSomeRegionReplicasColocated(cluster)) {
374-
LOG.info("Running balancer because at least one server hosts replicas of the same region.");
375+
LOG.info("Running balancer because at least one server hosts replicas of the same region." +
376+
" function cost={}", functionCost());
375377
return true;
376378
}
377379

378380
if (idleRegionServerExist(cluster)){
379-
LOG.info("Running balancer because cluster has idle server(s).");
381+
LOG.info("Running balancer because cluster has idle server(s)."+
382+
" function cost={}", functionCost());
380383
return true;
381384
}
382385

383-
sumMultiplier = 0.0f;
384386
double total = 0.0;
385387
for (CostFunction c : costFunctions) {
386-
float multiplier = c.getMultiplier();
387-
double cost = c.cost();
388388
if (!c.isNeeded()) {
389389
LOG.trace("{} not needed", c.getClass().getSimpleName());
390390
continue;
391391
}
392-
total += cost * multiplier;
393-
sumMultiplier += multiplier;
394-
}
395-
if (sumMultiplier <= 0) {
396-
LOG.error("At least one cost function needs a multiplier > 0. For example, set "
397-
+ "hbase.master.balancer.stochastic.regionCountCost to a positive value or default");
398-
return false;
392+
total += c.cost() * c.getMultiplier();
399393
}
400394

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

473467
initCosts(cluster);
468+
sumMultiplier = 0;
469+
for (CostFunction c : costFunctions) {
470+
if(c.isNeeded()) {
471+
sumMultiplier += c.getMultiplier();
472+
}
473+
}
474+
if (sumMultiplier <= 0) {
475+
LOG.error("At least one cost function needs a multiplier > 0. For example, set "
476+
+ "hbase.master.balancer.stochastic.regionCountCost to a positive value or default");
477+
return null;
478+
}
474479

475480
double currentCost = computeCost(cluster, Double.MAX_VALUE);
476481
curOverallCost = currentCost;
@@ -642,8 +647,8 @@ private String functionCost() {
642647
builder.append(", ");
643648
double cost = c.cost();
644649
builder.append("imbalance=" + cost);
645-
if (cost < minCostNeedBalance) {
646-
builder.append(", balanced");
650+
if (cost >= minCostNeedBalance) {
651+
builder.append(", need balance");
647652
}
648653
} else {
649654
builder.append("not needed");

0 commit comments

Comments
 (0)