-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-26308 Sum of multiplier of cost functions is not populated properly when we have a shortcut for trigger #3710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,7 +132,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; | ||
|
|
@@ -248,11 +248,12 @@ protected void loadConf(Configuration conf) { | |
| curFunctionCosts = new double[costFunctions.size()]; | ||
| tempFunctionCosts = new double[costFunctions.size()]; | ||
|
|
||
| LOG.info("Loaded config; maxSteps=" + maxSteps + ", runMaxSteps=" + runMaxSteps, | ||
| ", stepsPerRegion=" + stepsPerRegion + | ||
| ", maxRunningTime=" + maxRunningTime + ", isByTable=" + isByTable + ", CostFunctions=" + | ||
| Arrays.toString(getCostFunctionNames()) + " etc."); | ||
| } | ||
| LOG.info( | ||
| "Loaded config; maxSteps=" + maxSteps + ", runMaxSteps=" + runMaxSteps + | ||
| ", stepsPerRegion=" + stepsPerRegion + | ||
| ", maxRunningTime=" + maxRunningTime + ", isByTable=" + isByTable + | ||
| ", CostFunctions=" + Arrays.toString(getCostFunctionNames()) + | ||
| " , sum of multiplier of cost functions = " + sumMultiplier + " etc."); } | ||
|
|
||
| @Override | ||
| public void updateClusterMetrics(ClusterMetrics st) { | ||
|
|
@@ -345,33 +346,27 @@ boolean needsBalance(TableName tableName, BalancerClusterState 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 at least one server hosts replicas of the same region." + | ||
| "regionReplicaRackCostFunction={}", regionReplicaRackCostFunction.cost()); | ||
| 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; | ||
| total += c.cost() * 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 false; | ||
| } | ||
|
|
||
| boolean balanced = (total / sumMultiplier < minCostNeedBalance); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not update sumMultiplier but use it directly? It could be zero here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is moved up to the earlier stage before needsBalance is called so the short cut for idle server or cohosted replicas wouldn't get the wrong sum. |
||
|
|
||
| if (balanced) { | ||
|
|
@@ -435,6 +430,18 @@ protected List<RegionPlan> balanceTable(TableName tableName, Map<ServerName, | |
|
|
||
| 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; | ||
| System.arraycopy(tempFunctionCosts, 0, curFunctionCosts, 0, curFunctionCosts.length); | ||
|
|
@@ -598,8 +605,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"); | ||
Apache9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } else { | ||
| builder.append("not needed"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.