HBASE-24721: rename_rsgroup overwriting the existing rsgroup

Closes #2059

Signed-off-by: Reid Chan <reidchan@apache.org>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Mohammad Arshad 2020-07-14 21:24:18 +05:30 committed by Viraj Jasani
parent d132c4b53d
commit 70cfe2525e
No known key found for this signature in database
GPG Key ID: B3D6C0B41C8ADFD5
2 changed files with 57 additions and 1 deletions

View File

@ -1227,9 +1227,13 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
throw new ConstraintException(RSGroupInfo.DEFAULT_GROUP + " can't be rename");
}
checkGroupName(newName);
//getRSGroupInfo validates old RSGroup existence.
RSGroupInfo oldRSG = getRSGroupInfo(oldName);
Map<String, RSGroupInfo> rsGroupMap = holder.groupName2Group;
if (rsGroupMap.containsKey(newName)) {
throw new ConstraintException("Group already exists: " + newName);
}
Map<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
newGroupMap.remove(oldRSG.getName());
RSGroupInfo newRSG = new RSGroupInfo(newName, oldRSG.getServers());

View File

@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.rsgroup;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -534,4 +535,55 @@ public class TestRSGroupsAdmin1 extends TestRSGroupsBase {
assertEquals(newgroup.getName(), ADMIN.getRSGroup(tb1).getName());
assertEquals(normal.getName(), ADMIN.getRSGroup(tb2).getName());
}
@Test
public void testRenameRSGroupConstraints() throws Exception {
// Add RSGroup, and assign 2 servers and a table to it.
String oldGroupName = "oldGroup";
RSGroupInfo oldGroup = addGroup(oldGroupName, 2);
oldGroup = ADMIN.getRSGroup(oldGroup.getName());
assertNotNull(oldGroup);
assertEquals(2, oldGroup.getServers().size());
//Add another RSGroup
String anotherRSGroupName = "anotherRSGroup";
RSGroupInfo anotherGroup = addGroup(anotherRSGroupName, 1);
anotherGroup = ADMIN.getRSGroup(anotherGroup.getName());
assertNotNull(anotherGroup);
assertEquals(1, anotherGroup.getServers().size());
//Rename a non existing RSGroup
try {
ADMIN.renameRSGroup("nonExistingRSGroup", "newRSGroup1");
fail("ConstraintException was expected.");
} catch (ConstraintException e){
assertTrue(e.getMessage().contains("does not exist"));
}
//Rename to existing group
try {
ADMIN.renameRSGroup(oldGroup.getName(), anotherRSGroupName);
fail("ConstraintException was expected.");
} catch (ConstraintException e){
assertTrue(e.getMessage().contains("Group already exists"));
}
//Rename default RSGroup
try {
ADMIN.renameRSGroup(RSGroupInfo.DEFAULT_GROUP, "newRSGroup2");
fail("ConstraintException was expected.");
} catch (ConstraintException e){
//Do nothing
}
//Rename to default RSGroup
try {
ADMIN.renameRSGroup(oldGroup.getName(), RSGroupInfo.DEFAULT_GROUP);
fail("ConstraintException was expected.");
} catch (ConstraintException e){
assertTrue(e.getMessage().contains("Group already exists"));
}
}
}