hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-14604 Improve MoveCostFunction in StochasticLoadBalancer (Guanghao Zhang)
Date Tue, 20 Oct 2015 09:39:46 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 aaf565376 -> 76a14b9ba


HBASE-14604 Improve MoveCostFunction in StochasticLoadBalancer (Guanghao Zhang)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/76a14b9b
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/76a14b9b
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/76a14b9b

Branch: refs/heads/0.98
Commit: 76a14b9ba682c76a81baa06168239a2de6d2c7de
Parents: aaf5653
Author: tedyu <yuzhihong@gmail.com>
Authored: Tue Oct 20 02:39:38 2015 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Tue Oct 20 02:39:38 2015 -0700

----------------------------------------------------------------------
 .../hbase/master/balancer/BaseLoadBalancer.java | 16 +++++++++
 .../master/balancer/StochasticLoadBalancer.java |  2 +-
 .../balancer/TestStochasticLoadBalancer.java    | 34 ++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/76a14b9b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
index 3081811..0b6378f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
@@ -42,6 +42,7 @@ import org.apache.hadoop.hbase.master.AssignmentManager;
 import org.apache.hadoop.hbase.master.LoadBalancer;
 import org.apache.hadoop.hbase.master.MasterServices;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Sets;
@@ -314,6 +315,21 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
       }
     };
 
+    @VisibleForTesting
+    protected void setNumRegions(int numRegions) {
+      this.numRegions = numRegions;
+    }
+
+    @VisibleForTesting
+    protected void setNumMovedRegions(int numMovedRegions) {
+      this.numMovedRegions = numMovedRegions;
+    }
+
+    @VisibleForTesting
+    protected void setNumMovedMetaRegions(int numMovedMetaRegions) {
+      this.numMovedMetaRegions = numMovedMetaRegions;
+    }
+
     @Override
     public String toString() {
       String desc = "Cluster{" +

http://git-wip-us.apache.org/repos/asf/hbase/blob/76a14b9b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java
----------------------------------------------------------------------
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 9e1c9f5..8d9e268 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
@@ -704,7 +704,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
         moveCost += META_MOVE_COST_MULT * cluster.numMovedMetaRegions;
       }
 
-      return scale(0, cluster.numRegions + META_MOVE_COST_MULT, moveCost);
+      return scale(0, Math.min(cluster.numRegions, maxMoves) + META_MOVE_COST_MULT, moveCost);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/76a14b9b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java
----------------------------------------------------------------------
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 9f8ea42..3c59d27 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
@@ -200,6 +200,40 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
   }
 
   @Test
+  public void testMoveCost() throws Exception {
+    Configuration conf = HBaseConfiguration.create();
+    StochasticLoadBalancer.CostFunction
+        costFunction = new StochasticLoadBalancer.MoveCostFunction(conf);
+    for (int[] mockCluster : clusterStateMocks) {
+      BaseLoadBalancer.Cluster cluster = mockCluster(mockCluster);
+      double cost = costFunction.cost(cluster);
+      assertEquals(0.0f, cost, 0.001);
+
+      // cluster region number is smaller than maxMoves=600
+      cluster.setNumRegions(190);
+      cluster.setNumMovedRegions(10);
+      cost = costFunction.cost(cluster);
+      assertEquals(0.05f, cost, 0.001);
+      cluster.setNumMovedRegions(100);
+      cost = costFunction.cost(cluster);
+      assertEquals(0.5f, cost, 0.001);
+
+      // cluster region number is bigger than maxMoves=2500
+      cluster.setNumRegions(10000);
+      cluster.setNumMovedRegions(250);
+      cost = costFunction.cost(cluster);
+      assertEquals(0.1f, cost, 0.01);
+      cluster.setNumMovedRegions(1250);
+      cost = costFunction.cost(cluster);
+      assertEquals(0.5f, cost, 0.01);
+      cluster.setNumMovedRegions(2500);
+      cluster.setNumMovedMetaRegions(1);
+      cost = costFunction.cost(cluster);
+      assertEquals(1.0f, cost, 0.01);
+    }
+  }
+
+  @Test
   public void testSkewCost() {
     Configuration conf = HBaseConfiguration.create();
     StochasticLoadBalancer.CostFunction


Mime
View raw message