Search in sources :

Example 11 with InvalidFamilyOperationException

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);
}
Also used : InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) InterruptedIOException(java.io.InterruptedIOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 12 with InvalidFamilyOperationException

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);
}
Also used : InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) InterruptedIOException(java.io.InterruptedIOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 13 with InvalidFamilyOperationException

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);
    }
}
Also used : InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 14 with InvalidFamilyOperationException

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);
    }
}
Also used : InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 15 with InvalidFamilyOperationException

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.
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) FileSystem(org.apache.hadoop.fs.FileSystem) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Test(org.junit.Test)

Aggregations

InvalidFamilyOperationException (org.apache.hadoop.hbase.InvalidFamilyOperationException)15 Test (org.junit.Test)12 TableName (org.apache.hadoop.hbase.TableName)9 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)7 IOException (java.io.IOException)6 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)5 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)4 InterruptedIOException (java.io.InterruptedIOException)3 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)3 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)3 Admin (org.apache.hadoop.hbase.client.Admin)3 TableNotDisabledException (org.apache.hadoop.hbase.TableNotDisabledException)2 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)2 FileStatus (org.apache.hadoop.fs.FileStatus)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 PathFilter (org.apache.hadoop.fs.PathFilter)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1