Search in sources :

Example 1 with TableExistsException

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

the class TestLoadIncrementalHFilesSplitRecovery method setupTableWithSplitkeys.

/**
   * Creates a table with given table name,specified number of column families<br>
   * and splitkeys if the table does not already exist.
   * @param table
   * @param cfs
   * @param SPLIT_KEYS
   */
private void setupTableWithSplitkeys(TableName table, int cfs, byte[][] SPLIT_KEYS) throws IOException {
    try {
        LOG.info("Creating table " + table);
        HTableDescriptor htd = new HTableDescriptor(table);
        for (int i = 0; i < cfs; i++) {
            htd.addFamily(new HColumnDescriptor(family(i)));
        }
        util.createTable(htd, SPLIT_KEYS);
    } catch (TableExistsException tee) {
        LOG.info("Table " + table + " already exists");
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) TableExistsException(org.apache.hadoop.hbase.TableExistsException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 2 with TableExistsException

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

the class TestLoadIncrementalHFilesSplitRecovery method setupTable.

/**
   * Creates a table with given table name and specified number of column
   * families if the table does not already exist.
   */
private void setupTable(final Connection connection, TableName table, int cfs) throws IOException {
    try {
        LOG.info("Creating table " + table);
        HTableDescriptor htd = new HTableDescriptor(table);
        for (int i = 0; i < cfs; i++) {
            htd.addFamily(new HColumnDescriptor(family(i)));
        }
        try (Admin admin = connection.getAdmin()) {
            admin.createTable(htd);
        }
    } catch (TableExistsException tee) {
        LOG.info("Table " + table + " already exists");
    }
}
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)

Example 3 with TableExistsException

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

the class SchemaResource method replace.

private Response replace(final TableName name, final TableSchemaModel model, final UriInfo uriInfo, final Admin admin) {
    if (servlet.isReadOnly()) {
        return Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT).entity("Forbidden" + CRLF).build();
    }
    try {
        TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(name);
        for (Map.Entry<QName, Object> e : model.getAny().entrySet()) {
            tableDescriptorBuilder.setValue(e.getKey().getLocalPart(), e.getValue().toString());
        }
        for (ColumnSchemaModel family : model.getColumns()) {
            ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family.getName()));
            for (Map.Entry<QName, Object> e : family.getAny().entrySet()) {
                columnFamilyDescriptorBuilder.setValue(e.getKey().getLocalPart(), e.getValue().toString());
            }
            tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptorBuilder.build());
        }
        TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
        if (admin.tableExists(name)) {
            admin.disableTable(name);
            admin.modifyTable(tableDescriptor);
            admin.enableTable(name);
            servlet.getMetrics().incrementSucessfulPutRequests(1);
        } else {
            try {
                admin.createTable(tableDescriptor);
                servlet.getMetrics().incrementSucessfulPutRequests(1);
            } catch (TableExistsException e) {
                // race, someone else created a table with the same name
                return Response.status(Response.Status.NOT_MODIFIED).type(MIMETYPE_TEXT).entity("Not modified" + CRLF).build();
            }
        }
        return Response.created(uriInfo.getAbsolutePath()).build();
    } catch (Exception e) {
        LOG.info("Caught exception", e);
        servlet.getMetrics().incrementFailedPutRequests(1);
        return processException(e);
    }
}
Also used : QName(javax.xml.namespace.QName) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableExistsException(org.apache.hadoop.hbase.TableExistsException) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Map(java.util.Map) ColumnSchemaModel(org.apache.hadoop.hbase.rest.model.ColumnSchemaModel) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) WebApplicationException(org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException) IOException(java.io.IOException)

Example 4 with TableExistsException

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

the class CloneSnapshotProcedure method prepareClone.

/**
 * Action before any real action of cloning from snapshot.
 * @param env MasterProcedureEnv
 */
private void prepareClone(final MasterProcedureEnv env) throws IOException {
    final TableName tableName = getTableName();
    if (env.getMasterServices().getTableDescriptors().exists(tableName)) {
        throw new TableExistsException(tableName);
    }
    validateSFT();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableExistsException(org.apache.hadoop.hbase.TableExistsException)

Example 5 with TableExistsException

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

the class RawAsyncHBaseAdmin method cloneTableSchema.

@Override
public CompletableFuture<Void> cloneTableSchema(TableName tableName, TableName newTableName, boolean preserveSplits) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    addListener(tableExists(tableName), (exist, err) -> {
        if (err != null) {
            future.completeExceptionally(err);
            return;
        }
        if (!exist) {
            future.completeExceptionally(new TableNotFoundException(tableName));
            return;
        }
        addListener(tableExists(newTableName), (exist1, err1) -> {
            if (err1 != null) {
                future.completeExceptionally(err1);
                return;
            }
            if (exist1) {
                future.completeExceptionally(new TableExistsException(newTableName));
                return;
            }
            addListener(getDescriptor(tableName), (tableDesc, err2) -> {
                if (err2 != null) {
                    future.completeExceptionally(err2);
                    return;
                }
                TableDescriptor newTableDesc = TableDescriptorBuilder.copy(newTableName, tableDesc);
                if (preserveSplits) {
                    addListener(getTableSplits(tableName), (splits, err3) -> {
                        if (err3 != null) {
                            future.completeExceptionally(err3);
                        } else {
                            addListener(splits != null ? createTable(newTableDesc, splits) : createTable(newTableDesc), (result, err4) -> {
                                if (err4 != null) {
                                    future.completeExceptionally(err4);
                                } else {
                                    future.complete(result);
                                }
                            });
                        }
                    });
                } else {
                    addListener(createTable(newTableDesc), (result, err5) -> {
                        if (err5 != null) {
                            future.completeExceptionally(err5);
                        } else {
                            future.complete(result);
                        }
                    });
                }
            });
        });
    });
    return future;
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) CompletableFuture(java.util.concurrent.CompletableFuture) TableExistsException(org.apache.hadoop.hbase.TableExistsException)

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