use of org.apache.hadoop.hbase.InvalidFamilyOperationException in project hbase by apache.
the class HMaster method deleteColumn.
@Override
public long deleteColumn(final TableName tableName, final byte[] columnName, final long nonceGroup, final long nonce) throws IOException {
checkInitialized();
checkTableExists(tableName);
return modifyTable(tableName, new TableDescriptorGetter() {
@Override
public TableDescriptor get() throws IOException {
TableDescriptor old = getTableDescriptors().get(tableName);
if (!old.hasColumnFamily(columnName)) {
throw new InvalidFamilyOperationException("Family '" + Bytes.toString(columnName) + "' does not exist, so it cannot be deleted");
}
if (old.getColumnFamilyCount() == 1) {
throw new InvalidFamilyOperationException("Family '" + Bytes.toString(columnName) + "' is the only column family in the table, so it cannot be deleted");
}
return TableDescriptorBuilder.newBuilder(old).removeColumnFamily(columnName).build();
}
}, nonceGroup, nonce, true);
}
use of org.apache.hadoop.hbase.InvalidFamilyOperationException in project hbase by apache.
the class HMaster method modifyColumn.
@Override
public long modifyColumn(final TableName tableName, final ColumnFamilyDescriptor descriptor, final long nonceGroup, final long nonce) throws IOException {
checkInitialized();
checkTableExists(tableName);
return modifyTable(tableName, new TableDescriptorGetter() {
@Override
public TableDescriptor get() throws IOException {
TableDescriptor old = getTableDescriptors().get(tableName);
if (!old.hasColumnFamily(descriptor.getName())) {
throw new InvalidFamilyOperationException("Family '" + descriptor.getNameAsString() + "' does not exist, so it cannot be modified");
}
return TableDescriptorBuilder.newBuilder(old).modifyColumnFamily(descriptor).build();
}
}, nonceGroup, nonce, true);
}
use of org.apache.hadoop.hbase.InvalidFamilyOperationException in project hbase by apache.
the class TestTableDescriptorModificationFromClient method testAddSameColumnFamilyTwice.
@Test
public void testAddSameColumnFamilyTwice() throws IOException {
Admin admin = TEST_UTIL.getAdmin();
// Create a table with one families
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TABLE_NAME).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY_0)).build();
admin.createTable(tableDescriptor);
admin.disableTable(TABLE_NAME);
try {
// Verify the table descriptor
verifyTableDescriptor(TABLE_NAME, FAMILY_0);
// Modify the table removing one family and verify the descriptor
admin.addColumnFamily(TABLE_NAME, ColumnFamilyDescriptorBuilder.of(FAMILY_1));
verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
try {
// Add same column family again - expect failure
admin.addColumnFamily(TABLE_NAME, ColumnFamilyDescriptorBuilder.of(FAMILY_1));
Assert.fail("Delete a non-exist column family should fail");
} catch (InvalidFamilyOperationException e) {
// Expected.
}
} finally {
admin.deleteTable(TABLE_NAME);
}
}
use of org.apache.hadoop.hbase.InvalidFamilyOperationException in project hbase by apache.
the class TestTableDescriptorModificationFromClient method testModifyNonExistingColumnFamily.
@Test
public void testModifyNonExistingColumnFamily() throws IOException {
Admin admin = TEST_UTIL.getAdmin();
ColumnFamilyDescriptor cfDescriptor = ColumnFamilyDescriptorBuilder.of(FAMILY_1);
int blockSize = cfDescriptor.getBlocksize();
// Create a table with one families
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TABLE_NAME).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY_0)).build();
admin.createTable(tableDescriptor);
admin.disableTable(TABLE_NAME);
try {
// Verify the table descriptor
verifyTableDescriptor(TABLE_NAME, FAMILY_0);
int newBlockSize = 2 * blockSize;
cfDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(cfDescriptor).setBlocksize(newBlockSize).build();
// Modify a column family that is not in the table.
try {
admin.modifyColumnFamily(TABLE_NAME, cfDescriptor);
Assert.fail("Modify a non-exist column family should fail");
} catch (InvalidFamilyOperationException e) {
// Expected.
}
} finally {
admin.deleteTable(TABLE_NAME);
}
}
use of org.apache.hadoop.hbase.InvalidFamilyOperationException in project hbase by apache.
the class TestDeleteColumnFamilyProcedureFromClient method deleteColumnFamilyTwice.
@Test
public void deleteColumnFamilyTwice() throws Exception {
Admin admin = TEST_UTIL.getAdmin();
TableDescriptor beforehtd = admin.getDescriptor(TABLENAME);
String cfToDelete = "cf1";
FileSystem fs = TEST_UTIL.getDFSCluster().getFileSystem();
// 1 - Check if table exists in descriptor
assertTrue(admin.isTableAvailable(TABLENAME));
// 2 - Check if all the target column family exist in descriptor
ColumnFamilyDescriptor[] families = beforehtd.getColumnFamilies();
Boolean foundCF = false;
for (int i = 0; i < families.length; i++) {
if (families[i].getNameAsString().equals(cfToDelete)) {
foundCF = true;
break;
}
}
assertTrue(foundCF);
// 3 - Check if table exists in FS
Path tableDir = CommonFSUtils.getTableDir(TEST_UTIL.getDefaultRootDirPath(), TABLENAME);
assertTrue(fs.exists(tableDir));
// 4 - Check if all the target column family exist in FS
FileStatus[] fileStatus = fs.listStatus(tableDir);
foundCF = false;
for (int i = 0; i < fileStatus.length; i++) {
if (fileStatus[i].isDirectory() == true) {
FileStatus[] cf = fs.listStatus(fileStatus[i].getPath(), new PathFilter() {
@Override
public boolean accept(Path p) {
if (p.getName().contains(HConstants.RECOVERED_EDITS_DIR)) {
return false;
}
return true;
}
});
for (int j = 0; j < cf.length; j++) {
if (cf[j].isDirectory() == true && cf[j].getPath().getName().equals(cfToDelete)) {
foundCF = true;
break;
}
}
}
if (foundCF) {
break;
}
}
assertTrue(foundCF);
// TEST - Disable and delete the column family
if (admin.isTableEnabled(TABLENAME)) {
admin.disableTable(TABLENAME);
}
admin.deleteColumnFamily(TABLENAME, Bytes.toBytes(cfToDelete));
// 5 - Check if the target column family is gone from the FS
fileStatus = fs.listStatus(tableDir);
for (int i = 0; i < fileStatus.length; i++) {
if (fileStatus[i].isDirectory() == true) {
FileStatus[] cf = fs.listStatus(fileStatus[i].getPath(), new PathFilter() {
@Override
public boolean accept(Path p) {
if (WALSplitUtil.isSequenceIdFile(p)) {
return false;
}
return true;
}
});
for (int j = 0; j < cf.length; j++) {
if (cf[j].isDirectory() == true) {
assertFalse(cf[j].getPath().getName().equals(cfToDelete));
}
}
}
}
try {
// Test: delete again
admin.deleteColumnFamily(TABLENAME, Bytes.toBytes(cfToDelete));
Assert.fail("Delete a non-exist column family should fail");
} catch (InvalidFamilyOperationException e) {
// Expected.
}
}
Aggregations