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 ebe3d1d1d9
commit 5c902b48e5
2 changed files with 34 additions and 0 deletions

View File

@ -2189,6 +2189,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;
@ -6706,4 +6707,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);
}
}