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");
}
}
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");
}
}
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);
}
}
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();
}
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;
}
Aggregations