HBASE-24759 Refuse to update configuration of default group (#2126)

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
XinSun 2020-09-04 08:19:39 +08:00 committed by GitHub
parent 19b8a2a64a
commit c2721c8235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 31 deletions

View File

@ -216,15 +216,18 @@ public class RSGroupInfo {
return false;
}
RSGroupInfo RSGroupInfo = (RSGroupInfo) o;
RSGroupInfo rsGroupInfo = (RSGroupInfo) o;
if (!name.equals(RSGroupInfo.name)) {
if (!name.equals(rsGroupInfo.name)) {
return false;
}
if (!servers.equals(RSGroupInfo.servers)) {
if (!servers.equals(rsGroupInfo.servers)) {
return false;
}
if (!tables.equals(RSGroupInfo.tables)) {
if (!tables.equals(rsGroupInfo.tables)) {
return false;
}
if (!configuration.equals(rsGroupInfo.configuration)) {
return false;
}

View File

@ -696,7 +696,7 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
ZKUtil.createAndFailSilent(watcher, znode);
zkOps.add(ZKUtil.ZKUtilOp.deleteNodeFailSilent(znode));
zkOps.add(ZKUtil.ZKUtilOp.createAndFailSilent(znode,
ProtobufUtil.prependPBMagic(proto.toByteArray())));
ProtobufUtil.prependPBMagic(proto.toByteArray())));
}
}
LOG.debug("Writing ZK GroupInfo count: " + zkOps.size());
@ -1270,6 +1270,12 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
@Override
public synchronized void updateRSGroupConfig(String groupName, Map<String, String> configuration)
throws IOException {
if (RSGroupInfo.DEFAULT_GROUP.equals(groupName)) {
// We do not persist anything of default group, therefore, it is not supported to update
// default group's configuration which lost once master down.
throw new ConstraintException("configuration of " + RSGroupInfo.DEFAULT_GROUP
+ " can't be stored persistently");
}
RSGroupInfo rsGroupInfo = getRSGroupInfo(groupName);
rsGroupInfo.getConfiguration().forEach((k, v) -> rsGroupInfo.removeConfiguration(k));
configuration.forEach((k, v) -> rsGroupInfo.setConfiguration(k, v));

View File

@ -18,14 +18,12 @@
package org.apache.hadoop.hbase.rsgroup;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.constraint.ConstraintException;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RSGroupTests;
import org.junit.AfterClass;
@ -38,8 +36,6 @@ import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
@Category({ RSGroupTests.class, MediumTests.class })
public class TestRSGroupConfig extends TestRSGroupsBase {
@ -52,12 +48,9 @@ public class TestRSGroupConfig extends TestRSGroupsBase {
protected static final Logger LOG = LoggerFactory.getLogger(TestRSGroupConfig.class);
private static Admin admin;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TestRSGroupsBase.setUpTestBeforeClass();
admin = TEST_UTIL.getAdmin();
}
@AfterClass
@ -66,33 +59,30 @@ public class TestRSGroupConfig extends TestRSGroupsBase {
}
@Test
public void testSetDefaultGroupConfiguration() throws IOException {
testSetConfiguration(RSGroupInfo.DEFAULT_GROUP);
public void testSetDefaultGroupConfiguration() {
assertThrows(ConstraintException.class, () -> testSetConfiguration(RSGroupInfo.DEFAULT_GROUP));
}
@Test
public void testSetNonDefaultGroupConfiguration() throws IOException {
public void testSetNonDefaultGroupConfiguration() throws Exception {
String group = GROUP_PREFIX + name.getMethodName();
admin.addRSGroup(group);
testSetConfiguration(RSGroupInfo.DEFAULT_GROUP);
admin.removeRSGroup(group);
ADMIN.addRSGroup(group);
testSetConfiguration(group);
ADMIN.removeRSGroup(group);
}
private void testSetConfiguration(String group) throws IOException {
private void testSetConfiguration(String group) throws Exception {
Map<String, String> configuration = new HashMap<>();
configuration.put("aaa", "111");
configuration.put("bbb", "222");
admin.updateRSGroupConfig(group, configuration);
RSGroupInfo rsGroup = admin.getRSGroup(group);
Map<String, String> configFromGroup = Maps.newHashMap(rsGroup.getConfiguration());
assertNotNull(configFromGroup);
assertEquals(2, configFromGroup.size());
assertEquals("111", configFromGroup.get("aaa"));
ADMIN.updateRSGroupConfig(group, configuration);
RSGroupInfo rsGroup = ADMIN.getRSGroup(group);
assertEquals(configuration, rsGroup.getConfiguration());
// unset configuration
admin.updateRSGroupConfig(group, null);
rsGroup = admin.getRSGroup(group);
configFromGroup = rsGroup.getConfiguration();
assertNotNull(configFromGroup);
ADMIN.updateRSGroupConfig(group, null);
rsGroup = ADMIN.getRSGroup(group);
Map<String, String> configFromGroup = rsGroup.getConfiguration();
assertEquals(0, configFromGroup.size());
}