diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 60d0441aab6..3f13a45c360 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -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."; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index c4285b44687..5868869daf1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -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); + } }