From a8775b11d2c9ce822347e151aed603a3041e0233 Mon Sep 17 00:00:00 2001 From: Guangxu Cheng Date: Tue, 16 May 2017 12:58:20 +0800 Subject: [PATCH] HBASE-18051 balance_rsgroup still runs when the Load Balancer is not enabled Signed-off-by: tedyu --- .../hadoop/hbase/rsgroup/RSGroupAdminServer.java | 3 +++ .../org/apache/hadoop/hbase/rsgroup/TestRSGroups.java | 2 ++ .../apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java index 3c0cccf0096..718c7c1f5a1 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java @@ -38,6 +38,7 @@ import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.constraint.ConstraintException; import org.apache.hadoop.hbase.master.AssignmentManager; +import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.LoadBalancer; import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.master.RegionPlan; @@ -492,6 +493,8 @@ public class RSGroupAdminServer implements RSGroupAdmin { boolean balancerRan; synchronized (balancer) { + // If balance not true, don't run balancer. + if (!((HMaster) master).isBalancerOn()) return false; if (master.getMasterCoprocessorHost() != null) { master.getMasterCoprocessorHost().preBalanceRSGroup(groupName); } diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java index 6ef162b77f1..ae1485c2274 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java @@ -260,7 +260,9 @@ public class TestRSGroups extends TestRSGroupsBase { rsGroupAdminEndpoint.getGroupInfoManager() .moveTables(Sets.newHashSet(tableName), RSGroupInfo.getName()); + admin.setBalancerRunning(true,true); assertTrue(rsGroupAdmin.balanceRSGroup(RSGroupInfo.getName())); + admin.setBalancerRunning(false,true); TEST_UTIL.waitFor(60000, new Predicate() { @Override diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java index e5c89c37598..a99c24f9e47 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java @@ -210,7 +210,9 @@ public abstract class TestRSGroupsBase { } try { + admin.setBalancerRunning(true,true); rsGroupAdmin.balanceRSGroup("bogus"); + admin.setBalancerRunning(false,true); fail("Expected move with bogus group to fail"); } catch(ConstraintException ex) { //expected @@ -433,9 +435,17 @@ public abstract class TestRSGroupsBase { }); //balance the other group and make sure it doesn't affect the new group + admin.setBalancerRunning(true,true); rsGroupAdmin.balanceRSGroup(RSGroupInfo.DEFAULT_GROUP); assertEquals(6, getTableServerRegionMap().get(tableName).get(first).size()); + //disable balance, balancer will not be run and return false + admin.setBalancerRunning(false,true); + assertFalse(rsGroupAdmin.balanceRSGroup(newGroupName)); + assertEquals(6, getTableServerRegionMap().get(tableName).get(first).size()); + + //enable balance + admin.setBalancerRunning(true,true); rsGroupAdmin.balanceRSGroup(newGroupName); TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate() { @Override @@ -448,6 +458,7 @@ public abstract class TestRSGroupsBase { return true; } }); + admin.setBalancerRunning(false,true); } @Test