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 d17e297c343..0d0b5c1e854 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 @@ -1878,6 +1878,13 @@ public class HMaster extends HRegionServer implements MasterServices, Server { 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 (HColumnDescriptor 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 58ff20fe0f1..b63b27bd191 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 @@ -6547,4 +6547,25 @@ public class TestFromClientSide { } } + @Test(expected = DoNotRetryIOException.class) + public void testCreateTableWithZeroRegionReplicas() throws Exception { + TableName tableName = TableName.valueOf("testCreateTableWithZeroRegionReplicas"); + HTableDescriptor desc = new HTableDescriptor(tableName); + desc.addFamily(new HColumnDescriptor("cf")); + desc.setRegionReplication(0); + TEST_UTIL.getHBaseAdmin().createTable(desc); + } + + @Test(expected = DoNotRetryIOException.class) + public void testModifyTableWithZeroRegionReplicas() throws Exception { + TableName tableName = TableName.valueOf("testModifyTableWithZeroRegionReplicas"); + HTableDescriptor desc = new HTableDescriptor(tableName); + desc.addFamily(new HColumnDescriptor("cf")); + + TEST_UTIL.getHBaseAdmin().createTable(desc); + HTableDescriptor newDesc = new HTableDescriptor(desc); + newDesc.setRegionReplication(0); + + TEST_UTIL.getHBaseAdmin().modifyTable(tableName, newDesc); + } }