From 8095f96289ac2fb1f5d9cd15b3ef55ddf791020f Mon Sep 17 00:00:00 2001 From: Guangxu Cheng Date: Mon, 30 Oct 2017 16:57:10 +0800 Subject: [PATCH] HBASE-19088 move_tables_rsgroup will throw an exception when the table is disabled Signed-off-by: Andrew Purtell --- .../hbase/rsgroup/RSGroupAdminServer.java | 4 +++ .../hbase/rsgroup/TestRSGroupsBase.java | 33 +++++++++++++++++++ 2 files changed, 37 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 3c82d76b9e7..4a9a8858978 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 @@ -406,6 +406,10 @@ public class RSGroupAdminServer implements RSGroupAdmin { // action is required. if (targetGroup != null) { for (TableName table: tables) { + if (master.getAssignmentManager().isTableDisabled(table)) { + LOG.debug("Skipping move regions because the table" + table + " is disabled."); + continue; + } for (RegionInfo region : master.getAssignmentManager().getRegionStates().getRegionsOfTable(table)) { LOG.info("Moving region " + region.getShortNameToLog() + 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 f0291fadc44..b225dadf1a3 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 @@ -708,6 +708,39 @@ public abstract class TestRSGroupsBase { assertTrue(newGroupTables.contains(tableNameB)); } + @Test + public void testDisabledTableMove() throws Exception { + final byte[] familyNameBytes = Bytes.toBytes("f"); + String newGroupName = getGroupName(name.getMethodName()); + final RSGroupInfo newGroup = addGroup(newGroupName, 2); + + TEST_UTIL.createMultiRegionTable(tableName, familyNameBytes, 5); + TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate() { + @Override + public boolean evaluate() throws Exception { + List regions = getTableRegionMap().get(tableName); + if (regions == null) { + return false; + } + return getTableRegionMap().get(tableName).size() >= 5; + } + }); + + RSGroupInfo tableGrp = rsGroupAdmin.getRSGroupInfoOfTable(tableName); + assertTrue(tableGrp.getName().equals(RSGroupInfo.DEFAULT_GROUP)); + + //test disable table + admin.disableTable(tableName); + + //change table's group + LOG.info("Moving table "+ tableName + " to " + newGroup.getName()); + rsGroupAdmin.moveTables(Sets.newHashSet(tableName), newGroup.getName()); + + //verify group change + Assert.assertEquals(newGroup.getName(), + rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName()); + } + @Test public void testMoveServersAndTables() throws Exception { LOG.info("testMoveServersAndTables");