HBASE-21969 Improve the update of destination rsgroup of RSGroupInfoManagerImpl#moveTables()

This commit is contained in:
Xiang LI 2019-02-28 18:13:26 +08:00 committed by Xu Cang
parent b5c50b506c
commit 77a7e707ca
No known key found for this signature in database
GPG Key ID: 8E6C8FEDCA866394
1 changed files with 14 additions and 5 deletions

View File

@ -238,24 +238,33 @@ public class RSGroupInfoManagerImpl implements RSGroupInfoManager, ServerListene
@Override
public synchronized void moveTables(
Set<TableName> 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<String,RSGroupInfo> 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);
}