HBASE-25006 Make the cost functions optional for StochastoicBalancer

Closes #2386

Signed-off-by: Nick Dimiduk <ndimiduk@apache.org>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Clara Xiong 2020-09-13 14:10:58 +05:30 committed by Viraj Jasani
parent a0e25c4dc3
commit 4087743745
No known key found for this signature in database
GPG Key ID: B3D6C0B41C8ADFD5
1 changed files with 18 additions and 12 deletions

View File

@ -204,18 +204,18 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
regionReplicaRackCostFunction = new RegionReplicaRackCostFunction(conf);
costFunctions = new ArrayList<>();
costFunctions.add(new RegionCountSkewCostFunction(conf));
costFunctions.add(new PrimaryRegionCountSkewCostFunction(conf));
costFunctions.add(new MoveCostFunction(conf));
costFunctions.add(localityCost);
costFunctions.add(rackLocalityCost);
costFunctions.add(new TableSkewCostFunction(conf));
costFunctions.add(regionReplicaHostCostFunction);
costFunctions.add(regionReplicaRackCostFunction);
costFunctions.add(regionLoadFunctions[0]);
costFunctions.add(regionLoadFunctions[1]);
costFunctions.add(regionLoadFunctions[2]);
costFunctions.add(regionLoadFunctions[3]);
addCostFunction(new RegionCountSkewCostFunction(conf));
addCostFunction(new PrimaryRegionCountSkewCostFunction(conf));
addCostFunction(new MoveCostFunction(conf));
addCostFunction(localityCost);
addCostFunction(rackLocalityCost);
addCostFunction(new TableSkewCostFunction(conf));
addCostFunction(regionReplicaHostCostFunction);
addCostFunction(regionReplicaRackCostFunction);
addCostFunction(regionLoadFunctions[0]);
addCostFunction(regionLoadFunctions[1]);
addCostFunction(regionLoadFunctions[2]);
addCostFunction(regionLoadFunctions[3]);
loadCustomCostFunctions(conf);
curFunctionCosts = new Double[costFunctions.size()];
@ -513,6 +513,12 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
}
}
private void addCostFunction(CostFunction costFunction) {
if (costFunction.getMultiplier() > 0) {
costFunctions.add(costFunction);
}
}
private String functionCost() {
StringBuilder builder = new StringBuilder();
for (CostFunction c:costFunctions) {