virajjasani commented on a change in pull request #2044:
URL: https://github.com/apache/hbase/pull/2044#discussion_r456558482
##########
File path:
hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
##########
@@ -827,26 +828,34 @@ protected double scale(double min, double max, double
value) {
*/
static class MoveCostFunction extends CostFunction {
private static final String MOVE_COST_KEY =
"hbase.master.balancer.stochastic.moveCost";
+ private static final String MOVE_COST_OFFPEAK_KEY =
"hbase.master.balancer.stochastic.moveCost.offpeak";
private static final String MAX_MOVES_PERCENT_KEY =
"hbase.master.balancer.stochastic.maxMovePercent";
- private static final float DEFAULT_MOVE_COST = 7;
+ @VisibleForTesting
+ protected static final float DEFAULT_MOVE_COST = 7;
+ protected static final float DEFAULT_MOVE_COST_OFFPEAK = 3;
private static final int DEFAULT_MAX_MOVES = 600;
private static final float DEFAULT_MAX_MOVE_PERCENT = 0.25f;
private final float maxMovesPercent;
+ private final Configuration conf;
MoveCostFunction(Configuration conf) {
super(conf);
-
- // Move cost multiplier should be the same cost or higher than the rest
of the costs to ensure
- // that large benefits are need to overcome the cost of a move.
- this.setMultiplier(conf.getFloat(MOVE_COST_KEY, DEFAULT_MOVE_COST));
+ this.conf = conf;
// What percent of the number of regions a single run of the balancer
can move.
maxMovesPercent = conf.getFloat(MAX_MOVES_PERCENT_KEY,
DEFAULT_MAX_MOVE_PERCENT);
}
@Override
protected double cost() {
+ // Move cost multiplier should be the same cost or higher than the rest
of the costs to ensure
+ // that large benefits are need to overcome the cost of a move.
+ if (OffPeakHours.getInstance(conf).isOffPeakHour()) {
+ this.setMultiplier(conf.getFloat(MOVE_COST_OFFPEAK_KEY,
DEFAULT_MOVE_COST_OFFPEAK));
+ } else {
+ this.setMultiplier(conf.getFloat(MOVE_COST_KEY, DEFAULT_MOVE_COST));
+ }
Review comment:
@bsglz I just realized that whenever we update offpeak config
dynamically, `MoveCostFunction` constructor is called so we should better have
this logic in constructor only.
Check this out:
```
@Override
public void onConfigurationChange(Configuration conf) {
setConf(conf);
}
@Override
public synchronized void setConf(Configuration conf) {
super.setConf(conf);
...
...
costFunctions = new ArrayList<>();
costFunctions.add(new RegionCountSkewCostFunction(conf));
costFunctions.add(new PrimaryRegionCountSkewCostFunction(conf));
costFunctions.add(new MoveCostFunction(conf));
costFunctions.add(localityCost);
...
...
```
Hence, basically we can remove `this.conf = conf;` from this PR and move
this if condition to constructor.
When we try to update the config dynamically for SLB,
`onConfigurationChange()` is executed and that will reassign entire
constFunctions list.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]