HBASE-25726 MoveCostFunction is not included in the list of cost functions for StochasticLoadBalancer (#3116)

Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
d-c-manning 2021-04-02 09:22:13 -07:00 committed by GitHub
parent 446f22f05c
commit 7a31557c51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 6 deletions

View File

@ -900,6 +900,10 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
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

View File

@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.testclassification.MasterTests;
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;
@ -506,13 +507,40 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
@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){