HBASE-21645 Perform sanity check and disallow table creation/modification with region replication < 1

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
Nihal Jain 2019-01-08 23:24:08 +05:30 committed by Guanghao Zhang
parent 5364601dea
commit 111c827d1f
2 changed files with 34 additions and 0 deletions

View File

@ -2104,6 +2104,13 @@ public class HMaster extends HRegionServer implements MasterServices {
warnOrThrowExceptionForFailure(logWarn, CONF_KEY, message, null);
}
// check that we have minimum 1 region replicas
int regionReplicas = htd.getRegionReplication();
if (regionReplicas < 1) {
String message = "Table region replication should be at least one.";
warnOrThrowExceptionForFailure(logWarn, CONF_KEY, message, null);
}
for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) {
if (hcd.getTimeToLive() <= 0) {
String message = "TTL for column family " + hcd.getNameAsString() + " must be positive.";

View File

@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.CellScanner;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.ClusterMetrics.Option;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
@ -6707,4 +6708,30 @@ public class TestFromClientSide {
assertNull(scanner.next());
}
}
@Test(expected = DoNotRetryIOException.class)
public void testCreateTableWithZeroRegionReplicas() throws Exception {
TableName tableName = TableName.valueOf(name.getMethodName());
TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("cf")))
.setRegionReplication(0)
.build();
TEST_UTIL.getAdmin().createTable(desc);
}
@Test(expected = DoNotRetryIOException.class)
public void testModifyTableWithZeroRegionReplicas() throws Exception {
TableName tableName = TableName.valueOf(name.getMethodName());
TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("cf")))
.build();
TEST_UTIL.getAdmin().createTable(desc);
TableDescriptor newDesc = TableDescriptorBuilder.newBuilder(desc)
.setRegionReplication(0)
.build();
TEST_UTIL.getAdmin().modifyTable(newDesc);
}
}