hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chia7...@apache.org
Subject hbase git commit: HBASE-18480 The cost of BaseLoadBalancer.cluster is changed even if the rollback is done
Date Wed, 02 Aug 2017 00:41:35 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.4 2d9dbf27b -> 7b4cc8781


HBASE-18480 The cost of BaseLoadBalancer.cluster is changed even if the rollback is done


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

Branch: refs/heads/branch-1.4
Commit: 7b4cc8781cc5d62016fa7a60291fbc32c8b49f6d
Parents: 2d9dbf2
Author: Chia-Ping Tsai <chia7712@gmail.com>
Authored: Wed Aug 2 08:38:06 2017 +0800
Committer: Chia-Ping Tsai <chia7712@gmail.com>
Committed: Wed Aug 2 08:38:06 2017 +0800

----------------------------------------------------------------------
 .../hbase/master/balancer/BaseLoadBalancer.java |  1 +
 .../master/balancer/StochasticLoadBalancer.java | 11 +++++++---
 .../balancer/TestStochasticLoadBalancer.java    | 21 ++++++++++++++++++++
 3 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/7b4cc878/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 3bb12ce..f96f0eb 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
@@ -789,6 +789,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
       } else if (oldServer >= 0 && (numRegionsPerServerPerTable[oldServer][tableIndex]
+ 1)
           == numMaxRegionsPerTable[tableIndex]) {
         //recompute maxRegionsPerTable since the previous value was coming from the old server
+        numMaxRegionsPerTable[tableIndex] = 0;
         for (int serverIndex = 0 ; serverIndex < numRegionsPerServerPerTable.length; serverIndex++)
{
           if (numRegionsPerServerPerTable[serverIndex][tableIndex] > numMaxRegionsPerTable[tableIndex])
{
             numMaxRegionsPerTable[tableIndex] = numRegionsPerServerPerTable[serverIndex][tableIndex];

http://git-wip-us.apache.org/repos/asf/hbase/blob/7b4cc878/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 0f29a1a..3047d28 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
@@ -17,6 +17,7 @@
  */
 package org.apache.hadoop.hbase.master.balancer;
 
+import com.google.common.annotations.VisibleForTesting;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -316,6 +317,12 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
     return balanceCluster(clusterState);
   }
 
+  @VisibleForTesting
+  Cluster.Action nextAction(Cluster cluster) {
+    return candidateGenerators[(RANDOM.nextInt(candidateGenerators.length))]
+            .generate(cluster);
+  }
+
   /**
    * Given the cluster state this will try and approach an optimal balance. This
    * should always approach the optimal state given enough steps.
@@ -376,9 +383,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
     long step;
 
     for (step = 0; step < computedMaxSteps; step++) {
-      int generatorIdx = RANDOM.nextInt(candidateGenerators.length);
-      CandidateGenerator p = candidateGenerators[generatorIdx];
-      Cluster.Action action = p.generate(cluster);
+      Cluster.Action action = nextAction(cluster);
 
       if (action.type == Type.NULL) {
         continue;

http://git-wip-us.apache.org/repos/asf/hbase/blob/7b4cc878/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 125db06..ad459c1 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
@@ -279,6 +279,27 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
   }
 
   @Test
+  public void testCostAfterUndoAction() {
+    final int runs = 10;
+    loadBalancer.setConf(conf);
+    for (int[] mockCluster : clusterStateMocks) {
+      BaseLoadBalancer.Cluster cluster = mockCluster(mockCluster);
+      loadBalancer.initCosts(cluster);
+      for (int i = 0; i != runs; ++i) {
+        final double expectedCost = loadBalancer.computeCost(cluster, Double.MAX_VALUE);
+        Cluster.Action action = loadBalancer.nextAction(cluster);
+        cluster.doAction(action);
+        loadBalancer.updateCostsWithAction(cluster, action);
+        Cluster.Action undoAction = action.undoAction();
+        cluster.doAction(undoAction);
+        loadBalancer.updateCostsWithAction(cluster, undoAction);
+        final double actualCost = loadBalancer.computeCost(cluster, Double.MAX_VALUE);
+        assertEquals(expectedCost, actualCost, 0);
+      }
+    }
+  }
+
+  @Test
   public void testTableSkewCost() {
     Configuration conf = HBaseConfiguration.create();
     StochasticLoadBalancer.CostFunction


Mime
View raw message