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-14110 Add CostFunction for balancing primary region replicas
Date Fri, 17 Jul 2015 16:56:44 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 834f87b23 -> b98598f36


HBASE-14110 Add CostFunction for balancing primary region replicas


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

Branch: refs/heads/master
Commit: b98598f3638462a55434ea1426351fe78d72f154
Parents: 834f87b
Author: tedyu <yuzhihong@gmail.com>
Authored: Fri Jul 17 09:56:37 2015 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Fri Jul 17 09:56:37 2015 -0700

----------------------------------------------------------------------
 .../master/balancer/StochasticLoadBalancer.java | 41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/b98598f3/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 4955cfa..b6b4691 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
@@ -167,6 +167,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
 
     costFunctions = new CostFunction[]{
       new RegionCountSkewCostFunction(conf),
+      new PrimaryRegionCountSkewCostFunction(conf),
       new MoveCostFunction(conf),
       localityCost,
       new TableSkewCostFunction(conf),
@@ -947,6 +948,46 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
   }
 
   /**
+   * Compute the cost of a potential cluster state from skew in number of
+   * primary regions on a cluster.
+   */
+  static class PrimaryRegionCountSkewCostFunction extends CostFunction {
+    private static final String PRIMARY_REGION_COUNT_SKEW_COST_KEY =
+        "hbase.master.balancer.stochastic.primaryRegionCountCost";
+    private static final float DEFAULT_PRIMARY_REGION_COUNT_SKEW_COST = 500;
+
+    private double[] stats = null;
+
+    PrimaryRegionCountSkewCostFunction(Configuration conf) {
+      super(conf);
+      // Load multiplier should be the greatest as primary regions serve majority of reads/writes.
+      this.setMultiplier(conf.getFloat(PRIMARY_REGION_COUNT_SKEW_COST_KEY,
+        DEFAULT_PRIMARY_REGION_COUNT_SKEW_COST));
+    }
+
+    @Override
+    double cost() {
+      if (!cluster.hasRegionReplicas) {
+        return 0;
+      }
+      if (stats == null || stats.length != cluster.numServers) {
+        stats = new double[cluster.numServers];
+      }
+
+      for (int i =0; i < cluster.numServers; i++) {
+        stats[i] = 0;
+        for (int regionIdx : cluster.regionsPerServer[i]) {
+          if (regionIdx == cluster.regionIndexToPrimaryIndex[regionIdx]) {
+            stats[i] ++;
+          }
+        }
+      }
+
+      return costFromArray(stats);
+    }
+  }
+
+  /**
    * Compute the cost of a potential cluster configuration based upon how evenly
    * distributed tables are.
    */


Mime
View raw message