Skip to content

Commit

Permalink
HBASE-29073 StochasticLoadBalancer will always run the balancer on st…
Browse files Browse the repository at this point in the history
…artup because of uninitialized sumMultiplier (#6641) (#6650)

Signed-off-by: Nick Dimiduk <[email protected]>
Co-authored-by: Ray Mattingly <[email protected]>
  • Loading branch information
rmdmattingly and Ray Mattingly authored Jan 31, 2025
1 parent 2ac7ce6 commit cb7e46a
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,16 @@ boolean needsBalance(TableName tableName, BalancerClusterState cluster) {
}

double total = 0.0;
float localSumMultiplier = 0; // in case this.sumMultiplier is not initialized
for (CostFunction c : costFunctions) {
if (!c.isNeeded()) {
LOG.trace("{} not needed", c.getClass().getSimpleName());
continue;
}
total += c.cost() * c.getMultiplier();
localSumMultiplier += c.getMultiplier();
}

sumMultiplier = localSumMultiplier;
boolean balanced = (total / sumMultiplier < minCostNeedBalance);
if (balanced) {
if (isBalancerRejectionRecording) {
Expand Down Expand Up @@ -583,12 +585,13 @@ protected List<RegionPlan> balanceTable(TableName tableName,
long startTime = EnvironmentEdgeManager.currentTime();

initCosts(cluster);
sumMultiplier = 0;
float localSumMultiplier = 0;
for (CostFunction c : costFunctions) {
if (c.isNeeded()) {
sumMultiplier += c.getMultiplier();
localSumMultiplier += c.getMultiplier();
}
}
sumMultiplier = localSumMultiplier;
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");
Expand Down

0 comments on commit cb7e46a

Please sign in to comment.