HBASE-20500 [rsgroup] should keep at least one server in default group
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
1825af45b3
commit
102f0bf9c5
|
@ -56,6 +56,8 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
|
|||
@InterfaceAudience.Private
|
||||
public class RSGroupAdminServer implements RSGroupAdmin {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RSGroupAdminServer.class);
|
||||
public static final String KEEP_ONE_SERVER_IN_DEFAULT_ERROR_MESSAGE = "should keep at least " +
|
||||
"one server in 'default' RSGroup.";
|
||||
|
||||
private MasterServices master;
|
||||
private final RSGroupInfoManager rsGroupInfoManager;
|
||||
|
@ -307,6 +309,9 @@ public class RSGroupAdminServer implements RSGroupAdmin {
|
|||
// Only move online servers (when moving from 'default') or servers from other
|
||||
// groups. This prevents bogus servers from entering groups
|
||||
if (RSGroupInfo.DEFAULT_GROUP.equals(srcGrp.getName())) {
|
||||
if (srcGrp.getServers().size() <= servers.size()) {
|
||||
throw new ConstraintException(KEEP_ONE_SERVER_IN_DEFAULT_ERROR_MESSAGE);
|
||||
}
|
||||
checkOnlineServersOnly(servers);
|
||||
}
|
||||
// Ensure all servers are of same rsgroup.
|
||||
|
|
|
@ -339,6 +339,53 @@ public abstract class TestRSGroupsBase {
|
|||
Assert.assertEquals(null, rsGroupAdmin.getRSGroupInfo(fooGroup.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveServersFromDefaultGroup() throws Exception {
|
||||
//create groups and assign servers
|
||||
rsGroupAdmin.addRSGroup("foo");
|
||||
|
||||
RSGroupInfo fooGroup = rsGroupAdmin.getRSGroupInfo("foo");
|
||||
assertEquals(0, fooGroup.getServers().size());
|
||||
RSGroupInfo defaultGroup = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP);
|
||||
|
||||
//test remove all servers from default
|
||||
try {
|
||||
rsGroupAdmin.moveServers(defaultGroup.getServers(), fooGroup.getName());
|
||||
fail(RSGroupAdminServer.KEEP_ONE_SERVER_IN_DEFAULT_ERROR_MESSAGE);
|
||||
} catch (ConstraintException ex) {
|
||||
assertTrue(ex.getMessage().contains(RSGroupAdminServer
|
||||
.KEEP_ONE_SERVER_IN_DEFAULT_ERROR_MESSAGE));
|
||||
}
|
||||
|
||||
//test success case, remove one server from default ,keep at least one server
|
||||
if (defaultGroup.getServers().size() > 1) {
|
||||
Address serverInDefaultGroup = defaultGroup.getServers().iterator().next();
|
||||
LOG.info("moving server " + serverInDefaultGroup + " from group default to group " +
|
||||
fooGroup.getName());
|
||||
rsGroupAdmin.moveServers(Sets.newHashSet(serverInDefaultGroup), fooGroup.getName());
|
||||
}
|
||||
|
||||
fooGroup = rsGroupAdmin.getRSGroupInfo("foo");
|
||||
LOG.info("moving servers " + fooGroup.getServers() + " to group default");
|
||||
rsGroupAdmin.moveServers(fooGroup.getServers(), RSGroupInfo.DEFAULT_GROUP);
|
||||
|
||||
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
|
||||
@Override
|
||||
public boolean evaluate() throws Exception {
|
||||
return getNumServers() ==
|
||||
rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size();
|
||||
}
|
||||
});
|
||||
|
||||
fooGroup = rsGroupAdmin.getRSGroupInfo("foo");
|
||||
assertEquals(0, fooGroup.getServers().size());
|
||||
|
||||
//test group removal
|
||||
LOG.info("Remove group " + fooGroup.getName());
|
||||
rsGroupAdmin.removeRSGroup(fooGroup.getName());
|
||||
Assert.assertEquals(null, rsGroupAdmin.getRSGroupInfo(fooGroup.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableMoveTruncateAndDrop() throws Exception {
|
||||
final byte[] familyNameBytes = Bytes.toBytes("f");
|
||||
|
|
Loading…
Reference in New Issue