You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by vj...@apache.org on 2020/07/19 14:41:02 UTC

[hbase] branch master updated: HBASE-24709 Support MoveCostFunction use a lower multiplier in offpeak hours

This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b32943  HBASE-24709 Support MoveCostFunction use a lower multiplier in offpeak hours
9b32943 is described below

commit 9b329436976648f8ca7ea24cabe03cc44b922f87
Author: Zheng Wang <18...@qq.com>
AuthorDate: Sun Jul 19 20:05:49 2020 +0530

    HBASE-24709 Support MoveCostFunction use a lower multiplier in offpeak hours
    
    Closes #2099
    
    Signed-off-by: Viraj Jasani <vj...@apache.org>
    Signed-off-by: Mingliang Liu <li...@apache.org>
---
 .../master/balancer/StochasticLoadBalancer.java     | 19 ++++++++++++++-----
 .../master/balancer/TestStochasticLoadBalancer.java | 21 +++++++++++++++++++++
 2 files changed, 35 insertions(+), 5 deletions(-)

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 56b7ae4..786becd 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
@@ -46,6 +46,7 @@ import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.AssignRe
 import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.LocalityType;
 import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.MoveRegionAction;
 import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.SwapRegionsAction;
+import org.apache.hadoop.hbase.regionserver.compactions.OffPeakHours;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
 import org.apache.hadoop.hbase.util.ReflectionUtils;
 import org.apache.yetus.audience.InterfaceAudience;
@@ -827,26 +828,34 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
    */
   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;
+    static final float DEFAULT_MOVE_COST = 7;
+    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));
+      }
       // Try and size the max number of Moves, but always be prepared to move some.
       int maxMoves = Math.max((int) (cluster.numRegions * maxMovesPercent),
           DEFAULT_MAX_MOVES);
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 a01165d..4cb92a2 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
@@ -285,6 +285,27 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
   }
 
   @Test
+  public void testMoveCostMultiplier() throws Exception {
+    Configuration conf = HBaseConfiguration.create();
+    StochasticLoadBalancer.CostFunction
+      costFunction = new StochasticLoadBalancer.MoveCostFunction(conf);
+    BaseLoadBalancer.Cluster cluster = mockCluster(clusterStateMocks[0]);
+    costFunction.init(cluster);
+    costFunction.cost();
+    assertEquals(StochasticLoadBalancer.MoveCostFunction.DEFAULT_MOVE_COST,
+      costFunction.getMultiplier(), 0.01);
+
+    //In offpeak hours, the multiplier of move cost should be lower
+    conf.setInt("hbase.offpeak.start.hour",0);
+    conf.setInt("hbase.offpeak.end.hour",23);
+    costFunction = new StochasticLoadBalancer.MoveCostFunction(conf);
+    costFunction.init(cluster);
+    costFunction.cost();
+    assertEquals(StochasticLoadBalancer.MoveCostFunction.DEFAULT_MOVE_COST_OFFPEAK
+      , costFunction.getMultiplier(), 0.01);
+  }
+
+  @Test
   public void testMoveCost() throws Exception {
     Configuration conf = HBaseConfiguration.create();
     StochasticLoadBalancer.CostFunction