Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,10 @@ static class MoveCostFunction extends CostFunction {
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);

// Initialize the multiplier so that addCostFunction will add this cost function.
// It may change during later evaluations, due to OffPeakHours.
this.setMultiplier(conf.getFloat(MOVE_COST_KEY, DEFAULT_MOVE_COST));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down Expand Up @@ -506,13 +507,40 @@ public void testLosingRs() throws Exception {

@Test
public void testAdditionalCostFunction() {
conf.set(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY,
DummyCostFunction.class.getName());
try {
conf.set(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY,
DummyCostFunction.class.getName());

loadBalancer.setConf(conf);
assertTrue(Arrays.
asList(loadBalancer.getCostFunctionNames()).
contains(DummyCostFunction.class.getSimpleName()));
loadBalancer.setConf(conf);
assertTrue(Arrays.
asList(loadBalancer.getCostFunctionNames()).
contains(DummyCostFunction.class.getSimpleName()));
} finally {
conf.unset(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY);
loadBalancer.setConf(conf);
}
}

@Test
public void testDefaultCostFunctionList() {
List<String> expected = Arrays.asList(
StochasticLoadBalancer.RegionCountSkewCostFunction.class.getSimpleName(),
StochasticLoadBalancer.PrimaryRegionCountSkewCostFunction.class.getSimpleName(),
StochasticLoadBalancer.MoveCostFunction.class.getSimpleName(),
StochasticLoadBalancer.RackLocalityCostFunction.class.getSimpleName(),
StochasticLoadBalancer.TableSkewCostFunction.class.getSimpleName(),
StochasticLoadBalancer.RegionReplicaHostCostFunction.class.getSimpleName(),
StochasticLoadBalancer.RegionReplicaRackCostFunction.class.getSimpleName(),
StochasticLoadBalancer.ReadRequestCostFunction.class.getSimpleName(),
StochasticLoadBalancer.CPRequestCostFunction.class.getSimpleName(),
StochasticLoadBalancer.WriteRequestCostFunction.class.getSimpleName(),
StochasticLoadBalancer.MemStoreSizeCostFunction.class.getSimpleName(),
StochasticLoadBalancer.StoreFileCostFunction.class.getSimpleName()
);

List<String> actual = Arrays.asList(loadBalancer.getCostFunctionNames());
assertTrue("ExpectedCostFunctions: " + expected + " ActualCostFunctions: " + actual,
CollectionUtils.isEqualCollection(expected, actual));
}

private boolean needsBalanceIdleRegion(int[] cluster){
Expand Down