Search in sources :

Example 1 with InvalidFamilyOperationException

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

the class TestAdmin1 method testDeleteLastColumnFamily.

@Test(timeout = 300000)
public void testDeleteLastColumnFamily() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close();
    while (!this.admin.isTableEnabled(TableName.valueOf(name.getMethodName()))) {
        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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Test(org.junit.Test)

Example 2 with InvalidFamilyOperationException

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

the class TestAdmin1 method testDeleteEditUnknownColumnFamilyAndOrTable.

@Test(timeout = 300000)
public void testDeleteEditUnknownColumnFamilyAndOrTable() throws IOException {
    // Test we get exception if we try to
    final TableName nonexistentTable = TableName.valueOf("nonexistent");
    final byte[] nonexistentColumn = Bytes.toBytes("nonexistent");
    HColumnDescriptor nonexistentHcd = new HColumnDescriptor(nonexistentColumn);
    Exception exception = null;
    try {
        this.admin.addColumnFamily(nonexistentTable, nonexistentHcd);
    } catch (IOException e) {
        exception = e;
    }
    assertTrue(exception instanceof TableNotFoundException);
    exception = null;
    try {
        this.admin.deleteTable(nonexistentTable);
    } catch (IOException e) {
        exception = e;
    }
    assertTrue(exception instanceof TableNotFoundException);
    exception = null;
    try {
        this.admin.deleteColumnFamily(nonexistentTable, nonexistentColumn);
    } catch (IOException e) {
        exception = e;
    }
    assertTrue(exception instanceof TableNotFoundException);
    exception = null;
    try {
        this.admin.disableTable(nonexistentTable);
    } catch (IOException e) {
        exception = e;
    }
    assertTrue(exception instanceof TableNotFoundException);
    exception = null;
    try {
        this.admin.enableTable(nonexistentTable);
    } catch (IOException e) {
        exception = e;
    }
    assertTrue(exception instanceof TableNotFoundException);
    exception = null;
    try {
        this.admin.modifyColumnFamily(nonexistentTable, nonexistentHcd);
    } catch (IOException e) {
        exception = e;
    }
    assertTrue(exception instanceof TableNotFoundException);
    exception = null;
    try {
        HTableDescriptor htd = new HTableDescriptor(nonexistentTable);
        htd.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
        this.admin.modifyTable(htd.getTableName(), htd);
    } catch (IOException e) {
        exception = e;
    }
    assertTrue(exception instanceof TableNotFoundException);
    // Now make it so at least the table exists and then do tests against a
    // nonexistent column family -- see if we get right exceptions.
    final TableName tableName = TableName.valueOf(name.getMethodName() + System.currentTimeMillis());
    HTableDescriptor htd = new HTableDescriptor(tableName);
    htd.addFamily(new HColumnDescriptor("cf"));
    this.admin.createTable(htd);
    try {
        exception = null;
        try {
            this.admin.deleteColumnFamily(htd.getTableName(), nonexistentHcd.getName());
        } catch (IOException e) {
            exception = e;
        }
        assertTrue("found=" + exception.getClass().getName(), exception instanceof InvalidFamilyOperationException);
        exception = null;
        try {
            this.admin.modifyColumnFamily(htd.getTableName(), nonexistentHcd);
        } catch (IOException e) {
            exception = e;
        }
        assertTrue("found=" + exception.getClass().getName(), exception instanceof InvalidFamilyOperationException);
    } finally {
        this.admin.disableTable(tableName);
        this.admin.deleteTable(tableName);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) IOException(java.io.IOException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) MergeRegionException(org.apache.hadoop.hbase.exceptions.MergeRegionException) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) IOException(java.io.IOException) TableNotDisabledException(org.apache.hadoop.hbase.TableNotDisabledException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 3 with InvalidFamilyOperationException

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

the class TestDeleteColumnFamilyProcedure method testDeleteColumnFamilyTwice.

@Test(timeout = 60000)
public void testDeleteColumnFamilyTwice() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    final String cf2 = "cf2";
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1", cf2);
    // delete the column family that exists
    long procId1 = procExec.submitProcedure(new DeleteColumnFamilyProcedure(procExec.getEnvironment(), tableName, cf2.getBytes()));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    // First delete should succeed
    ProcedureTestingUtility.assertProcNotFailed(procExec, procId1);
    MasterProcedureTestingUtility.validateColumnFamilyDeletion(UTIL.getHBaseCluster().getMaster(), tableName, cf2);
    // delete the column family that does not exist
    long procId2 = procExec.submitProcedure(new DeleteColumnFamilyProcedure(procExec.getEnvironment(), tableName, cf2.getBytes()));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    // Second delete should fail with InvalidFamilyOperationException
    ProcedureInfo result = procExec.getResult(procId2);
    assertTrue(result.isFailed());
    LOG.debug("Delete online failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof InvalidFamilyOperationException);
    // Try again, this time with table disabled.
    UTIL.getAdmin().disableTable(tableName);
    long procId3 = procExec.submitProcedure(new DeleteColumnFamilyProcedure(procExec.getEnvironment(), tableName, cf2.getBytes()));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId3);
    // Expect fail with InvalidFamilyOperationException
    result = procExec.getResult(procId2);
    assertTrue(result.isFailed());
    LOG.debug("Delete offline failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof InvalidFamilyOperationException);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) Test(org.junit.Test)

Example 4 with InvalidFamilyOperationException

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

the class HMaster method addColumn.

@Override
public long addColumn(final TableName tableName, final ColumnFamilyDescriptor column, 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(column.getName())) {
                throw new InvalidFamilyOperationException("Column family '" + column.getNameAsString() + "' in table '" + tableName + "' already exists so cannot be added");
            }
            return TableDescriptorBuilder.newBuilder(old).setColumnFamily(column).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 5 with InvalidFamilyOperationException

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

the class TestModifyTableProcedure method testColumnFamilyAdditionTwiceWithNonce.

@Test
public void testColumnFamilyAdditionTwiceWithNonce() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final String cf2 = "cf2";
    final String cf3 = "cf3";
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    // create the table
    RegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName, null, "cf1", cf3);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Modify multiple properties of the table.
    TableDescriptor td = UTIL.getAdmin().getDescriptor(tableName);
    TableDescriptor newTd = TableDescriptorBuilder.newBuilder(td).setCompactionEnabled(!td.isCompactionEnabled()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf2)).build();
    PerClientRandomNonceGenerator nonceGenerator = PerClientRandomNonceGenerator.get();
    long nonceGroup = nonceGenerator.getNonceGroup();
    long newNonce = nonceGenerator.newNonce();
    NonceKey nonceKey = new NonceKey(nonceGroup, newNonce);
    procExec.registerNonce(nonceKey);
    // Start the Modify procedure && kill the executor
    final long procId = procExec.submitProcedure(new ModifyTableProcedure(procExec.getEnvironment(), newTd), nonceKey);
    // Restart the executor after MODIFY_TABLE_UPDATE_TABLE_DESCRIPTOR and try to add column family
    // as nonce are there , we should not fail
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId, new StepHook() {

        @Override
        public boolean execute(int step) throws IOException {
            if (step == 3) {
                return procId == UTIL.getHBaseCluster().getMaster().addColumn(tableName, ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(cf2)).build(), nonceGroup, newNonce);
            }
            return true;
        }
    });
    // Try with different nonce, now it should fail the checks
    try {
        UTIL.getHBaseCluster().getMaster().addColumn(tableName, ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(cf2)).build(), nonceGroup, nonceGenerator.newNonce());
        Assert.fail();
    } catch (InvalidFamilyOperationException e) {
    }
    // Validate descriptor
    TableDescriptor currentHtd = UTIL.getAdmin().getDescriptor(tableName);
    assertEquals(!td.isCompactionEnabled(), currentHtd.isCompactionEnabled());
    assertEquals(3, currentHtd.getColumnFamilyCount());
    assertTrue(currentHtd.hasColumnFamily(Bytes.toBytes(cf2)));
    assertTrue(currentHtd.hasColumnFamily(Bytes.toBytes(cf3)));
    // cf2 should be added
    MasterProcedureTestingUtility.validateTableCreation(UTIL.getHBaseCluster().getMaster(), tableName, regions, "cf1", cf2, cf3);
}
Also used : PerClientRandomNonceGenerator(org.apache.hadoop.hbase.client.PerClientRandomNonceGenerator) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) TableName(org.apache.hadoop.hbase.TableName) StepHook(org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility.StepHook) NonceKey(org.apache.hadoop.hbase.util.NonceKey) 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