HBASE-13812 Deleting of last Column Family of a table should not be allowed
This commit is contained in:
parent
ee30d050dc
commit
ae803d72fe
|
@ -284,6 +284,11 @@ public class DeleteColumnFamilyProcedure
|
|||
throw new InvalidFamilyOperationException("Family '" + getColumnFamilyName()
|
||||
+ "' does not exist, so it cannot be deleted");
|
||||
}
|
||||
|
||||
if (unmodifiedHTableDescriptor.getColumnFamilies().length == 1) {
|
||||
throw new InvalidFamilyOperationException("Family '" + getColumnFamilyName()
|
||||
+ "' is the only column family in the table, so it cannot be deleted");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,7 +60,6 @@ import org.apache.hadoop.hbase.testclassification.ClientTests;
|
|||
import org.apache.hadoop.hbase.testclassification.LargeTests;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.util.Pair;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
|
@ -1279,10 +1278,9 @@ public class TestAdmin1 {
|
|||
|
||||
@Test (timeout=300000)
|
||||
public void testEnableDisableAddColumnDeleteColumn() throws Exception {
|
||||
ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);
|
||||
TableName tableName = TableName.valueOf("testMasterAdmin");
|
||||
TableName tableName = TableName.valueOf("testEnableDisableAddColumnDeleteColumn");
|
||||
TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close();
|
||||
while (!this.admin.isTableEnabled(TableName.valueOf("testMasterAdmin"))) {
|
||||
while (!this.admin.isTableEnabled(TableName.valueOf("testEnableDisableAddColumnDeleteColumn"))) {
|
||||
Thread.sleep(10);
|
||||
}
|
||||
this.admin.disableTable(tableName);
|
||||
|
@ -1302,4 +1300,33 @@ public class TestAdmin1 {
|
|||
this.admin.disableTable(tableName);
|
||||
this.admin.deleteTable(tableName);
|
||||
}
|
||||
|
||||
@Test (timeout=300000)
|
||||
public void testDeleteLastColumnFamily() throws Exception {
|
||||
TableName tableName = TableName.valueOf("testDeleteLastColumnFamily");
|
||||
TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close();
|
||||
while (!this.admin.isTableEnabled(TableName.valueOf("testDeleteLastColumnFamily"))) {
|
||||
Thread.sleep(10);
|
||||
}
|
||||
|
||||
// test for enabled table
|
||||
try {
|
||||
this.admin.deleteColumnFamily(tableName, HConstants.CATALOG_FAMILY);
|
||||
fail("Should have failed to delete the only column family of a table");
|
||||
} catch (InvalidFamilyOperationException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
// test for disabled table
|
||||
this.admin.disableTable(tableName);
|
||||
|
||||
try {
|
||||
this.admin.deleteColumnFamily(tableName, HConstants.CATALOG_FAMILY);
|
||||
fail("Should have failed to delete the only column family of a table");
|
||||
} catch (InvalidFamilyOperationException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
this.admin.deleteTable(tableName);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue