Search in sources :

Example 1 with ConcurrentTableModificationException

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

the class TestModifyTableProcedure method testConcurrentModifyTable.

@Test
public void testConcurrentModifyTable() throws IOException, InterruptedException {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    UTIL.createTable(tableName, column_Family1);
    class ConcurrentModifyTable extends Thread {

        TableName tableName = null;

        TableDescriptor htd = null;

        boolean exception;

        public ConcurrentModifyTable(TableName tableName, TableDescriptor htd) {
            this.tableName = tableName;
            this.htd = htd;
            this.exception = false;
        }

        public void run() {
            try {
                UTIL.getAdmin().modifyTable(htd);
            } catch (Exception e) {
                if (e.getClass().equals(ConcurrentTableModificationException.class)) {
                    this.exception = true;
                }
            }
        }
    }
    TableDescriptor htd = UTIL.getAdmin().getDescriptor(tableName);
    TableDescriptor modifiedDescriptor = TableDescriptorBuilder.newBuilder(htd).setCompactionEnabled(false).build();
    ConcurrentModifyTable t1 = new ConcurrentModifyTable(tableName, modifiedDescriptor);
    ConcurrentModifyTable t2 = new ConcurrentModifyTable(tableName, modifiedDescriptor);
    t1.start();
    t2.start();
    t1.join();
    t2.join();
    assertFalse("Expected ConcurrentTableModificationException.", (t1.exception || t2.exception));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) Test(org.junit.Test)

Example 2 with ConcurrentTableModificationException

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

the class TestModifyTableProcedure method testConcurrentDeleteColumnFamily.

@Test
public void testConcurrentDeleteColumnFamily() throws IOException, InterruptedException {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName);
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column_Family1)).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column_Family2)).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column_Family3)).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    UTIL.getAdmin().createTable(tableDescriptorBuilder.build());
    class ConcurrentCreateDeleteTable extends Thread {

        TableName tableName = null;

        String columnFamily = null;

        boolean exception;

        public ConcurrentCreateDeleteTable(TableName tableName, String columnFamily) {
            this.tableName = tableName;
            this.columnFamily = columnFamily;
            this.exception = false;
        }

        public void run() {
            try {
                UTIL.getAdmin().deleteColumnFamily(tableName, columnFamily.getBytes());
            } catch (Exception e) {
                if (e.getClass().equals(ConcurrentTableModificationException.class)) {
                    this.exception = true;
                }
            }
        }
    }
    ConcurrentCreateDeleteTable t1 = new ConcurrentCreateDeleteTable(tableName, column_Family2);
    ConcurrentCreateDeleteTable t2 = new ConcurrentCreateDeleteTable(tableName, column_Family3);
    t1.start();
    t2.start();
    t1.join();
    t2.join();
    int noOfColumnFamilies = UTIL.getAdmin().getDescriptor(tableName).getColumnFamilies().length;
    assertTrue("Expected ConcurrentTableModificationException.", ((t1.exception || t2.exception) && noOfColumnFamilies == 2) || noOfColumnFamilies == 1);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) Test(org.junit.Test)

Example 3 with ConcurrentTableModificationException

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

the class ModifyTableProcedure method prepareModify.

/**
 * Check conditions before any real action of modifying a table.
 */
private void prepareModify(final MasterProcedureEnv env) throws IOException {
    // Checks whether the table exists
    if (!env.getMasterServices().getTableDescriptors().exists(getTableName())) {
        throw new TableNotFoundException(getTableName());
    }
    // check that we have at least 1 CF
    if (modifiedTableDescriptor.getColumnFamilyCount() == 0) {
        throw new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family.");
    }
    // for comparison in order to update the descriptor.
    if (shouldCheckDescriptor) {
        if (TableDescriptor.COMPARATOR.compare(unmodifiedTableDescriptor, env.getMasterServices().getTableDescriptors().get(getTableName())) != 0) {
            LOG.error("Error while modifying table '" + getTableName().toString() + "' Skipping procedure : " + this);
            throw new ConcurrentTableModificationException("Skipping modify table operation on table '" + getTableName().toString() + "' as it has already been modified by some other concurrent operation, " + "Please retry.");
        }
    } else {
        this.unmodifiedTableDescriptor = env.getMasterServices().getTableDescriptors().get(getTableName());
    }
    this.deleteColumnFamilyInModify = isDeleteColumnFamily(unmodifiedTableDescriptor, modifiedTableDescriptor);
    if (!unmodifiedTableDescriptor.getRegionServerGroup().equals(modifiedTableDescriptor.getRegionServerGroup())) {
        Supplier<String> forWhom = () -> "table " + getTableName();
        RSGroupInfo rsGroupInfo = MasterProcedureUtil.checkGroupExists(env.getMasterServices().getRSGroupInfoManager()::getRSGroup, modifiedTableDescriptor.getRegionServerGroup(), forWhom);
        MasterProcedureUtil.checkGroupNotEmpty(rsGroupInfo, forWhom);
    }
    // check for store file tracker configurations
    StoreFileTrackerValidationUtils.checkForModifyTable(env.getMasterConfiguration(), unmodifiedTableDescriptor, modifiedTableDescriptor);
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) RSGroupInfo(org.apache.hadoop.hbase.rsgroup.RSGroupInfo)

Example 4 with ConcurrentTableModificationException

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

the class TestModifyTableProcedure method testConcurrentAddColumnFamily.

@Test
public void testConcurrentAddColumnFamily() throws IOException, InterruptedException {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    UTIL.createTable(tableName, column_Family1);
    class ConcurrentAddColumnFamily extends Thread {

        TableName tableName = null;

        ColumnFamilyDescriptor columnFamilyDescriptor;

        boolean exception;

        public ConcurrentAddColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamilyDescriptor) {
            this.tableName = tableName;
            this.columnFamilyDescriptor = columnFamilyDescriptor;
            this.exception = false;
        }

        public void run() {
            try {
                UTIL.getAdmin().addColumnFamily(tableName, columnFamilyDescriptor);
            } catch (Exception e) {
                if (e.getClass().equals(ConcurrentTableModificationException.class)) {
                    this.exception = true;
                }
            }
        }
    }
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column_Family2)).build();
    ConcurrentAddColumnFamily t1 = new ConcurrentAddColumnFamily(tableName, columnFamilyDescriptor);
    columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column_Family3)).build();
    ConcurrentAddColumnFamily t2 = new ConcurrentAddColumnFamily(tableName, columnFamilyDescriptor);
    t1.start();
    t2.start();
    t1.join();
    t2.join();
    int noOfColumnFamilies = UTIL.getAdmin().getDescriptor(tableName).getColumnFamilies().length;
    assertTrue("Expected ConcurrentTableModificationException.", ((t1.exception || t2.exception) && noOfColumnFamilies == 2) || noOfColumnFamilies == 3);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) Test(org.junit.Test)

Example 5 with ConcurrentTableModificationException

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

the class TestModifyTableProcedure method testConcurrentModifyColumnFamily.

@Test
public void testConcurrentModifyColumnFamily() throws IOException, InterruptedException {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    UTIL.createTable(tableName, column_Family1);
    class ConcurrentModifyColumnFamily extends Thread {

        TableName tableName = null;

        ColumnFamilyDescriptor hcd = null;

        boolean exception;

        public ConcurrentModifyColumnFamily(TableName tableName, ColumnFamilyDescriptor hcd) {
            this.tableName = tableName;
            this.hcd = hcd;
            this.exception = false;
        }

        public void run() {
            try {
                UTIL.getAdmin().modifyColumnFamily(tableName, hcd);
            } catch (Exception e) {
                if (e.getClass().equals(ConcurrentTableModificationException.class)) {
                    this.exception = true;
                }
            }
        }
    }
    ColumnFamilyDescriptor modColumnFamily1 = ColumnFamilyDescriptorBuilder.newBuilder(column_Family1.getBytes()).setMaxVersions(5).build();
    ColumnFamilyDescriptor modColumnFamily2 = ColumnFamilyDescriptorBuilder.newBuilder(column_Family1.getBytes()).setMaxVersions(6).build();
    ConcurrentModifyColumnFamily t1 = new ConcurrentModifyColumnFamily(tableName, modColumnFamily1);
    ConcurrentModifyColumnFamily t2 = new ConcurrentModifyColumnFamily(tableName, modColumnFamily2);
    t1.start();
    t2.start();
    t1.join();
    t2.join();
    int maxVersions = UTIL.getAdmin().getDescriptor(tableName).getColumnFamily(column_Family1.getBytes()).getMaxVersions();
    assertTrue("Expected ConcurrentTableModificationException.", (t1.exception && maxVersions == 5) || (t2.exception && maxVersions == 6) || !(t1.exception && t2.exception));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) Test(org.junit.Test)

Aggregations

ConcurrentTableModificationException (org.apache.hadoop.hbase.ConcurrentTableModificationException)5 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)5 IOException (java.io.IOException)4 InvalidFamilyOperationException (org.apache.hadoop.hbase.InvalidFamilyOperationException)4 TableName (org.apache.hadoop.hbase.TableName)4 Test (org.junit.Test)4 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)3 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)1 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)1 RSGroupInfo (org.apache.hadoop.hbase.rsgroup.RSGroupInfo)1