From 8ac2f7a7b2989f46388676063d0e58e9068f65ba Mon Sep 17 00:00:00 2001 From: Xiang LI Date: Thu, 28 Feb 2019 18:13:26 +0800 Subject: [PATCH] HBASE-21969 Improve the update of destination rsgroup of RSGroupInfoManagerImpl#moveTables() --- .../hbase/rsgroup/RSGroupInfoManagerImpl.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java index 4c4e302cd8..12c4faff8b 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java @@ -238,24 +238,33 @@ public class RSGroupInfoManagerImpl implements RSGroupInfoManager, ServerListene @Override public synchronized void moveTables( Set tableNames, String groupName) throws IOException { + // Check if rsGroup contains the destination rsgroup if (groupName != null && !rsGroupMap.containsKey(groupName)) { throw new DoNotRetryIOException("Group "+groupName+" does not exist"); } + // Make a copy of rsGroupMap to update Map newGroupMap = Maps.newHashMap(rsGroupMap); + + // Remove tables from their original rsgroups + // and update the copy of rsGroupMap for(TableName tableName: tableNames) { if (tableMap.containsKey(tableName)) { RSGroupInfo src = new RSGroupInfo(newGroupMap.get(tableMap.get(tableName))); src.removeTable(tableName); newGroupMap.put(src.getName(), src); } - if(groupName != null) { - RSGroupInfo dst = new RSGroupInfo(newGroupMap.get(groupName)); - dst.addTable(tableName); - newGroupMap.put(dst.getName(), dst); - } } + // Add tables to the destination rsgroup + // and update the copy of rsGroupMap + if (groupName != null) { + RSGroupInfo dstGroup = new RSGroupInfo(newGroupMap.get(groupName)); + dstGroup.addAllTables(tableNames); + newGroupMap.put(dstGroup.getName(), dstGroup); + } + + // Flush according to the updated copy of rsGroupMap flushConfig(newGroupMap); } -- 2.20.1