HBASE-21645 Perform sanity check and disallow table creation/modification with region replication < 1
Signed-off-by: Guanghao Zhang <zghao@apache.org> Conflicts: hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Amending-Author: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
cad3630c70
commit
0546b77a31
|
@ -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.";
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue