diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java index 30b5fca02a5..d64bac2bb7e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java @@ -1238,6 +1238,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 diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java index e32e972b816..3dfb44ee8bf 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java @@ -35,6 +35,7 @@ import java.util.Queue; import java.util.TimeZone; import java.util.TreeMap; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -55,8 +56,8 @@ import org.apache.hadoop.hbase.testclassification.FlakeyTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdge; -import org.junit.Ignore; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -716,7 +717,7 @@ public class TestStochasticLoadBalancer extends BalancerTestBase { @Test public void testAdditionalCostFunction() { conf.set(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY, - DummyCostFunction.class.getName()); + DummyCostFunction.class.getName()); loadBalancer.setConf(conf); System.out.println(Arrays.toString(loadBalancer.getCostFunctionNames())); @@ -725,6 +726,27 @@ public class TestStochasticLoadBalancer extends BalancerTestBase { contains(DummyCostFunction.class.getSimpleName())); } + @Test + public void testDefaultCostFunctionList() { + List 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.WriteRequestCostFunction.class.getSimpleName(), + StochasticLoadBalancer.MemstoreSizeCostFunction.class.getSimpleName(), + StochasticLoadBalancer.StoreFileCostFunction.class.getSimpleName() + ); + + List actual = Arrays.asList(loadBalancer.getCostFunctionNames()); + assertTrue("ExpectedCostFunctions: " + expected + " ActualCostFunctions: " + actual, + CollectionUtils.isEqualCollection(expected, actual)); + } + private boolean needsBalanceIdleRegion(int[] clusters) { boolean b1 = false; boolean b2 = false;