@@ -152,7 +152,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
152
152
private List <CandidateGenerator > candidateGenerators ;
153
153
private List <CostFunction > costFunctions ; // FindBugs: Wants this protected; IS2_INCONSISTENT_SYNC
154
154
// 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 ;
156
156
// to save and report costs to JMX
157
157
private double curOverallCost = 0d ;
158
158
private double [] tempFunctionCosts ;
@@ -248,8 +248,9 @@ public synchronized void setConf(Configuration conf) {
248
248
LOG .info (
249
249
"Loaded config; maxSteps=" + maxSteps + ", runMaxSteps=" + runMaxSteps +
250
250
", 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." );
253
254
}
254
255
255
256
private void loadCustomCostFunctions (Configuration conf ) {
@@ -371,31 +372,24 @@ protected boolean needsBalance(TableName tableName, Cluster cluster) {
371
372
return false ;
372
373
}
373
374
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 ());
375
377
return true ;
376
378
}
377
379
378
380
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 ());
380
383
return true ;
381
384
}
382
385
383
- sumMultiplier = 0.0f ;
384
386
double total = 0.0 ;
385
387
for (CostFunction c : costFunctions ) {
386
- float multiplier = c .getMultiplier ();
387
- double cost = c .cost ();
388
388
if (!c .isNeeded ()) {
389
389
LOG .trace ("{} not needed" , c .getClass ().getSimpleName ());
390
390
continue ;
391
391
}
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 ();
399
393
}
400
394
401
395
boolean balanced = (total / sumMultiplier < minCostNeedBalance );
@@ -471,6 +465,17 @@ public synchronized List<RegionPlan> balanceTable(TableName tableName, Map<Serve
471
465
long startTime = EnvironmentEdgeManager .currentTime ();
472
466
473
467
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
+ }
474
479
475
480
double currentCost = computeCost (cluster , Double .MAX_VALUE );
476
481
curOverallCost = currentCost ;
@@ -642,8 +647,8 @@ private String functionCost() {
642
647
builder .append (", " );
643
648
double cost = c .cost ();
644
649
builder .append ("imbalance=" + cost );
645
- if (cost < minCostNeedBalance ) {
646
- builder .append (", balanced " );
650
+ if (cost >= minCostNeedBalance ) {
651
+ builder .append (", need balance " );
647
652
}
648
653
} else {
649
654
builder .append ("not needed" );
0 commit comments