HBASE-24721: rename_rsgroup overwriting the existing rsgroup
Closes #2066 Co-authored-by: Viraj Jasani <vjasani@apache.org> Signed-off-by: Reid Chan <reidchan@apache.org> Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
parent
e5b2334124
commit
f5080eb9a6
|
@ -850,6 +850,9 @@ public class RSGroupInfoManagerImpl implements RSGroupInfoManager, ServerListene
|
||||||
if (oldName.equals(RSGroupInfo.DEFAULT_GROUP)) {
|
if (oldName.equals(RSGroupInfo.DEFAULT_GROUP)) {
|
||||||
throw new ConstraintException("Can't rename default rsgroup");
|
throw new ConstraintException("Can't rename default rsgroup");
|
||||||
}
|
}
|
||||||
|
if (rsGroupMap.containsKey(newName)) {
|
||||||
|
throw new ConstraintException("Group already exists: " + newName);
|
||||||
|
}
|
||||||
|
|
||||||
RSGroupInfo oldGroup = getRSGroup(oldName);
|
RSGroupInfo oldGroup = getRSGroup(oldName);
|
||||||
Map<String,RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
|
Map<String,RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.rsgroup;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
@ -519,4 +520,45 @@ public class TestRSGroupsAdmin1 extends TestRSGroupsBase {
|
||||||
assertTrue(newgroup.containsTable(tb1));
|
assertTrue(newgroup.containsTable(tb1));
|
||||||
assertEquals(normal.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tb2).getName());
|
assertEquals(normal.getName(), rsGroupAdmin.getRSGroupInfoOfTable(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(rsGroupAdmin, oldGroupName, 2);
|
||||||
|
oldGroup = rsGroupAdmin.getRSGroupInfo(oldGroup.getName());
|
||||||
|
assertNotNull(oldGroup);
|
||||||
|
assertEquals(2, oldGroup.getServers().size());
|
||||||
|
|
||||||
|
//Add another RSGroup
|
||||||
|
String anotherRSGroupName = "anotherRSGroup";
|
||||||
|
RSGroupInfo anotherGroup = addGroup(rsGroupAdmin, anotherRSGroupName, 1);
|
||||||
|
anotherGroup = rsGroupAdmin.getRSGroupInfo(anotherGroup.getName());
|
||||||
|
assertNotNull(anotherGroup);
|
||||||
|
assertEquals(1, anotherGroup.getServers().size());
|
||||||
|
|
||||||
|
//Rename to existing group
|
||||||
|
try {
|
||||||
|
rsGroupAdmin.renameRSGroup(oldGroup.getName(), anotherRSGroupName);
|
||||||
|
fail("ConstraintException was expected.");
|
||||||
|
} catch (ConstraintException e) {
|
||||||
|
assertTrue(e.getMessage().contains("Group already exists"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Rename default RSGroup
|
||||||
|
try {
|
||||||
|
rsGroupAdmin.renameRSGroup(RSGroupInfo.DEFAULT_GROUP, "newRSGroup2");
|
||||||
|
fail("ConstraintException was expected.");
|
||||||
|
} catch (ConstraintException e) {
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
//Rename to default RSGroup
|
||||||
|
try {
|
||||||
|
rsGroupAdmin.renameRSGroup(oldGroup.getName(), RSGroupInfo.DEFAULT_GROUP);
|
||||||
|
fail("ConstraintException was expected.");
|
||||||
|
} catch (ConstraintException e) {
|
||||||
|
assertTrue(e.getMessage().contains("Group already exists"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue