Search in sources :

Example 11 with TableExistsException

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

the class TestRestartCluster method testClusterRestart.

@Test(timeout = 300000)
public void testClusterRestart() throws Exception {
    UTIL.startMiniCluster(3);
    while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {
        Threads.sleep(1);
    }
    LOG.info("\n\nCreating tables");
    for (TableName TABLE : TABLES) {
        UTIL.createTable(TABLE, FAMILY);
    }
    for (TableName TABLE : TABLES) {
        UTIL.waitTableEnabled(TABLE);
    }
    List<HRegionInfo> allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);
    assertEquals(4, allRegions.size());
    LOG.info("\n\nShutting down cluster");
    UTIL.shutdownMiniHBaseCluster();
    LOG.info("\n\nSleeping a bit");
    Thread.sleep(2000);
    LOG.info("\n\nStarting cluster the second time");
    UTIL.restartHBaseCluster(3);
    // Need to use a new 'Configuration' so we make a new Connection.
    // Otherwise we're reusing an Connection that has gone stale because
    // the shutdown of the cluster also called shut of the connection.
    allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);
    assertEquals(4, allRegions.size());
    LOG.info("\n\nWaiting for tables to be available");
    for (TableName TABLE : TABLES) {
        try {
            UTIL.createTable(TABLE, FAMILY);
            assertTrue("Able to create table that should already exist", false);
        } catch (TableExistsException tee) {
            LOG.info("Table already exists as expected");
        }
        UTIL.waitTableAvailable(TABLE);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) TableExistsException(org.apache.hadoop.hbase.TableExistsException) Test(org.junit.Test)

Example 12 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project phoenix by apache.

the class ConnectionQueryServicesImpl method createSysMutexTable.

private void createSysMutexTable(HBaseAdmin admin) throws IOException, SQLException {
    try {
        final TableName mutexTableName = TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES);
        List<TableName> systemTables = getSystemTableNames(admin);
        if (systemTables.contains(mutexTableName)) {
            logger.debug("System mutex table already appears to exist, not creating it");
            return;
        }
        HTableDescriptor tableDesc = new HTableDescriptor(mutexTableName);
        HColumnDescriptor columnDesc = new HColumnDescriptor(PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES);
        // Let mutex expire after some time
        columnDesc.setTimeToLive(TTL_FOR_MUTEX);
        tableDesc.addFamily(columnDesc);
        admin.createTable(tableDesc);
        try (HTableInterface sysMutexTable = getTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES)) {
            byte[] mutexRowKey = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA, PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE);
            Put put = new Put(mutexRowKey);
            put.add(PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES, UPGRADE_MUTEX, UPGRADE_MUTEX_UNLOCKED);
            sysMutexTable.put(put);
        }
    } catch (TableExistsException e) {
    // Ignore
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) TableExistsException(org.apache.hadoop.hbase.TableExistsException) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 13 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project ranger by apache.

the class RangerAccessControlLists method init.

public static void init(MasterServices master) throws IOException {
    Class<AccessControlLists> accessControlListsClass = AccessControlLists.class;
    String cName = accessControlListsClass.getName();
    Class<?>[] params = new Class[1];
    params[0] = MasterServices.class;
    for (String mname : new String[] { "init", "createACLTable" }) {
        try {
            try {
                Method m = accessControlListsClass.getDeclaredMethod(mname, params);
                if (m != null) {
                    try {
                        try {
                            m.invoke(null, master);
                            logInfo("Execute method name [" + mname + "] in Class [" + cName + "] is successful.");
                        } catch (InvocationTargetException e) {
                            Throwable cause = e;
                            boolean tableExistsExceptionFound = false;
                            if (e != null) {
                                Throwable ecause = e.getTargetException();
                                if (ecause != null) {
                                    cause = ecause;
                                    if (ecause instanceof TableExistsException) {
                                        tableExistsExceptionFound = true;
                                    }
                                }
                            }
                            if (!tableExistsExceptionFound) {
                                logError("Unable to execute the method [" + mname + "] on [" + cName + "] due to exception", cause);
                                throw new IOException(cause);
                            }
                        }
                        return;
                    } catch (IllegalArgumentException e) {
                        logError("Unable to execute method name [" + mname + "] in Class [" + cName + "].", e);
                        throw new IOException(e);
                    } catch (IllegalAccessException e) {
                        logError("Unable to execute method name [" + mname + "] in Class [" + cName + "].", e);
                        throw new IOException(e);
                    }
                }
            } catch (NoSuchMethodException nsme) {
                logInfo("Unable to get method name [" + mname + "] in Class [" + cName + "]. Ignoring the exception");
            }
        } catch (SecurityException e) {
            logError("Unable to get method name [" + mname + "] in Class [" + cName + "].", e);
            throw new IOException(e);
        }
    }
    throw new IOException("Unable to initialize() [" + cName + "]");
}
Also used : Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TableExistsException(org.apache.hadoop.hbase.TableExistsException)

Example 14 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project cdap by caskdata.

the class DefaultHBaseDDLExecutor method createTableIfNotExists.

@Override
public void createTableIfNotExists(TableDescriptor descriptor, @Nullable byte[][] splitKeys) throws IOException {
    HTableDescriptor htd = getHTableDescriptor(descriptor);
    if (admin.tableExists(htd.getName())) {
        return;
    }
    boolean tableExistsFailure = false;
    try {
        LOG.debug("Attempting to create table '{}' if it does not exist", Bytes.toString(htd.getName()));
        admin.createTable(htd, splitKeys);
    } catch (TableExistsException e) {
        // table may exist because someone else is creating it at the same
        // time. But it may not be available yet, and opening it might fail.
        LOG.debug("Table '{}' already exists.", Bytes.toString(htd.getName()), e);
        tableExistsFailure = true;
    }
    // Wait for table to materialize
    try {
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.start();
        long sleepTime = TimeUnit.MILLISECONDS.toNanos(5000L) / 10;
        sleepTime = sleepTime <= 0 ? 1 : sleepTime;
        do {
            if (admin.tableExists(htd.getName())) {
                if (tableExistsFailure) {
                    LOG.info("Table '{}' exists now. Assuming that another process concurrently created it.", Bytes.toString(htd.getName()));
                } else {
                    LOG.info("Table '{}' created.", Bytes.toString(htd.getName()));
                }
                return;
            } else {
                TimeUnit.NANOSECONDS.sleep(sleepTime);
            }
        } while (stopwatch.elapsedTime(TimeUnit.MILLISECONDS) < 5000L);
    } catch (InterruptedException e) {
        LOG.warn("Sleeping thread interrupted.");
    }
    LOG.error("Table '{}' does not exist after waiting {} ms. Giving up.", Bytes.toString(htd.getName()), MAX_CREATE_TABLE_WAIT);
}
Also used : TableExistsException(org.apache.hadoop.hbase.TableExistsException) Stopwatch(com.google.common.base.Stopwatch) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 15 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project cdap by caskdata.

the class DefaultHBaseTransactionPruningPlugin method createPruneTable.

// We need to copy this method from the parent class since the HTableDescriptor#addFamily method returns void
// in HBase 1.2-CDH5.7.0 while it returns HTableDescriptor HBase 1.1 which is what the tephra-hbase-compat-1.1 module
// depends on.
@Override
protected void createPruneTable(TableName stateTable) throws IOException {
    try (Admin admin = this.connection.getAdmin()) {
        if (admin.tableExists(stateTable)) {
            LOG.debug("Not creating pruneStateTable {} since it already exists.", stateTable.getNameWithNamespaceInclAsString());
            return;
        }
        HTableDescriptor htd = new HTableDescriptor(stateTable);
        htd.addFamily(new HColumnDescriptor(DataJanitorState.FAMILY).setMaxVersions(1));
        admin.createTable(htd);
        LOG.info("Created pruneTable {}", stateTable.getNameWithNamespaceInclAsString());
    } catch (TableExistsException ex) {
        // Expected if the prune state table is being created at the same time by another client
        LOG.debug("Not creating pruneStateTable {} since it already exists.", stateTable.getNameWithNamespaceInclAsString(), ex);
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) TableExistsException(org.apache.hadoop.hbase.TableExistsException) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Aggregations

TableExistsException (org.apache.hadoop.hbase.TableExistsException)22 TableName (org.apache.hadoop.hbase.TableName)9 IOException (java.io.IOException)7 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)7 Test (org.junit.Test)7 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)5 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)4 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)3 Map (java.util.Map)2 Admin (org.apache.hadoop.hbase.client.Admin)2 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)2 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)2 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1