HBASE-25838 Use double instead of Double in StochasticLoadBalancer (#3221)
Signed-off-by: Yulin Niu <niuyulin@apache.org>
This commit is contained in:
parent
a7814bbe57
commit
08507b86a8
|
@ -145,9 +145,9 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
private List<CostFunction> costFunctions; // FindBugs: Wants this protected; IS2_INCONSISTENT_SYNC
|
private List<CostFunction> costFunctions; // FindBugs: Wants this protected; IS2_INCONSISTENT_SYNC
|
||||||
|
|
||||||
// to save and report costs to JMX
|
// to save and report costs to JMX
|
||||||
private Double curOverallCost = 0d;
|
private double curOverallCost = 0d;
|
||||||
private Double[] tempFunctionCosts;
|
private double[] tempFunctionCosts;
|
||||||
private Double[] curFunctionCosts;
|
private double[] curFunctionCosts;
|
||||||
|
|
||||||
// Keep locality based picker and cost function to alert them
|
// Keep locality based picker and cost function to alert them
|
||||||
// when new services are offered
|
// when new services are offered
|
||||||
|
@ -222,8 +222,8 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
addCostFunction(regionLoadFunctions[3]);
|
addCostFunction(regionLoadFunctions[3]);
|
||||||
loadCustomCostFunctions(conf);
|
loadCustomCostFunctions(conf);
|
||||||
|
|
||||||
curFunctionCosts = new Double[costFunctions.size()];
|
curFunctionCosts = new double[costFunctions.size()];
|
||||||
tempFunctionCosts = new Double[costFunctions.size()];
|
tempFunctionCosts = new double[costFunctions.size()];
|
||||||
|
|
||||||
boolean isBalancerDecisionRecording = getConf()
|
boolean isBalancerDecisionRecording = getConf()
|
||||||
.getBoolean(BaseLoadBalancer.BALANCER_DECISION_BUFFER_ENABLED,
|
.getBoolean(BaseLoadBalancer.BALANCER_DECISION_BUFFER_ENABLED,
|
||||||
|
@ -523,8 +523,10 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
/**
|
/**
|
||||||
* update costs to JMX
|
* update costs to JMX
|
||||||
*/
|
*/
|
||||||
private void updateStochasticCosts(TableName tableName, Double overall, Double[] subCosts) {
|
private void updateStochasticCosts(TableName tableName, double overall, double[] subCosts) {
|
||||||
if (tableName == null) return;
|
if (tableName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// check if the metricsBalancer is MetricsStochasticBalancer before casting
|
// check if the metricsBalancer is MetricsStochasticBalancer before casting
|
||||||
if (metricsBalancer instanceof MetricsStochasticBalancer) {
|
if (metricsBalancer instanceof MetricsStochasticBalancer) {
|
||||||
|
@ -537,7 +539,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
for (int i = 0; i < costFunctions.size(); i++) {
|
for (int i = 0; i < costFunctions.size(); i++) {
|
||||||
CostFunction costFunction = costFunctions.get(i);
|
CostFunction costFunction = costFunctions.get(i);
|
||||||
String costFunctionName = costFunction.getClass().getSimpleName();
|
String costFunctionName = costFunction.getClass().getSimpleName();
|
||||||
Double costPercent = (overall == 0) ? 0 : (subCosts[i] / overall);
|
double costPercent = (overall == 0) ? 0 : (subCosts[i] / overall);
|
||||||
// TODO: cost function may need a specific description
|
// TODO: cost function may need a specific description
|
||||||
balancer.updateStochasticCost(tableName.getNameAsString(), costFunctionName,
|
balancer.updateStochasticCost(tableName.getNameAsString(), costFunctionName,
|
||||||
"The percent of " + costFunctionName, costPercent);
|
"The percent of " + costFunctionName, costPercent);
|
||||||
|
@ -686,7 +688,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
}
|
}
|
||||||
|
|
||||||
Float multiplier = c.getMultiplier();
|
Float multiplier = c.getMultiplier();
|
||||||
Double cost = c.cost();
|
double cost = c.cost();
|
||||||
|
|
||||||
this.tempFunctionCosts[i] = multiplier*cost;
|
this.tempFunctionCosts[i] = multiplier*cost;
|
||||||
total += this.tempFunctionCosts[i];
|
total += this.tempFunctionCosts[i];
|
||||||
|
|
Loading…
Reference in New Issue