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:
parent
ebe3d1d1d9
commit
5c902b48e5
|
@ -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.";
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue