Search in sources :

Example 6 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();
    HTableDescriptor beforehtd = admin.getTableDescriptor(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
    HColumnDescriptor[] 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 = FSUtils.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 (WALSplitter.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) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) FileSystem(org.apache.hadoop.fs.FileSystem) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Test(org.junit.Test)

Example 7 with InvalidFamilyOperationException

use of org.apache.hadoop.hbase.InvalidFamilyOperationException in project hbase by apache.

the class TestAddColumnFamilyProcedure method testAddSameColumnFamilyTwice.

@Test(timeout = 60000)
public void testAddSameColumnFamilyTwice() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final String cf2 = "cf2";
    final HColumnDescriptor columnDescriptor = new HColumnDescriptor(cf2);
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1");
    // add the column family
    long procId1 = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    ProcedureTestingUtility.assertProcNotFailed(procExec, procId1);
    MasterProcedureTestingUtility.validateColumnFamilyAddition(UTIL.getHBaseCluster().getMaster(), tableName, cf2);
    // add the column family that exists
    long procId2 = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    // Second add should fail with InvalidFamilyOperationException
    ProcedureInfo result = procExec.getResult(procId2);
    assertTrue(result.isFailed());
    LOG.debug("Add failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof InvalidFamilyOperationException);
    // Do the same add the existing column family - this time offline
    UTIL.getAdmin().disableTable(tableName);
    long procId3 = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId3);
    // Second add should fail with InvalidFamilyOperationException
    result = procExec.getResult(procId3);
    assertTrue(result.isFailed());
    LOG.debug("Add failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof InvalidFamilyOperationException);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Test(org.junit.Test)

Example 8 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();
    HColumnDescriptor cfDescriptor = new HColumnDescriptor(FAMILY_1);
    int blockSize = cfDescriptor.getBlocksize();
    // Create a table with one families
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
        // Verify the table descriptor
        verifyTableDescriptor(TABLE_NAME, FAMILY_0);
        int newBlockSize = 2 * blockSize;
        cfDescriptor.setBlocksize(newBlockSize);
        // 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 : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 9 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
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
    admin.createTable(baseHtd);
    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, new HColumnDescriptor(FAMILY_1));
        verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
        try {
            // Add same column family again - expect failure
            admin.addColumnFamily(TABLE_NAME, new HColumnDescriptor(FAMILY_1));
            Assert.fail("Delete a non-exist column family should fail");
        } catch (InvalidFamilyOperationException e) {
        // Expected.
        }
    } finally {
        admin.deleteTable(TABLE_NAME);
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Aggregations

InvalidFamilyOperationException (org.apache.hadoop.hbase.InvalidFamilyOperationException)9 Test (org.junit.Test)9 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)6 TableName (org.apache.hadoop.hbase.TableName)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)4 Admin (org.apache.hadoop.hbase.client.Admin)3 IOException (java.io.IOException)1 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 MasterNotRunningException (org.apache.hadoop.hbase.MasterNotRunningException)1 TableNotDisabledException (org.apache.hadoop.hbase.TableNotDisabledException)1 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 ZooKeeperConnectionException (org.apache.hadoop.hbase.ZooKeeperConnectionException)1 MergeRegionException (org.apache.hadoop.hbase.exceptions.MergeRegionException)1