From dc1310f48731c6855d7df7a93dea773e4d46e579 Mon Sep 17 00:00:00 2001 From: Guangxu Cheng Date: Mon, 30 Oct 2017 16:29:40 +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 | 7 ++++ .../hbase/rsgroup/TestRSGroupsBase.java | 34 +++++++++++++++++++ 2 files changed, 41 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 13b3141b803..125e08ee573 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 @@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.hbase.master.ServerManager; import org.apache.hadoop.hbase.master.TableLockManager.TableLock; import org.apache.hadoop.hbase.net.Address; +import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; /** * Service to support Region Server Grouping (HBase-6721) @@ -276,6 +277,12 @@ public class RSGroupAdminServer implements RSGroupAdmin { } } for(TableName table: tables) { + if (master.getAssignmentManager().getTableStateManager().isTableState(table, + ZooKeeperProtos.Table.State.DISABLED, + ZooKeeperProtos.Table.State.DISABLING)) { + LOG.debug("Skipping move regions because the table" + table + " is disabled."); + continue; + } TableLock lock = master.getTableLockManager().writeLock(table, "Group: table move"); try { lock.acquire(); 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 0db0feac0c5..a0d1401ae24 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 @@ -812,4 +812,38 @@ public abstract class TestRSGroupsBase { Set newGroupTables = rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables(); assertTrue(newGroupTables.contains(tableName)); } + + @Test + public void testDisabledTableMove() throws Exception { + final TableName tableName = TableName.valueOf(tablePrefix + "_testDisabledTableMove"); + final byte[] familyNameBytes = Bytes.toBytes("f"); + String newGroupName = getGroupName("testDisabledTableMove"); + final RSGroupInfo newGroup = addGroup(rsGroupAdmin, 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()); + } }