use of org.apache.hadoop.hbase.thrift.generated.IllegalArgument in project hbase by apache.
the class ThriftHBaseServiceHandler method mutateRowTs.
@Override
public void mutateRowTs(ByteBuffer tableName, ByteBuffer row, List<Mutation> mutations, long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError, IllegalArgument {
Table table = null;
try {
table = getTable(tableName);
Put put = new Put(getBytes(row), timestamp);
addAttributes(put, attributes);
Delete delete = new Delete(getBytes(row));
addAttributes(delete, attributes);
if (metrics != null) {
metrics.incNumRowKeysInBatchMutate(mutations.size());
}
// I apologize for all this mess :)
CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
for (Mutation m : mutations) {
byte[][] famAndQf = CellUtil.parseColumn(getBytes(m.column));
if (m.isDelete) {
if (famAndQf.length == 1) {
delete.addFamily(famAndQf[0], timestamp);
} else {
delete.addColumns(famAndQf[0], famAndQf[1], timestamp);
}
delete.setDurability(m.writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
} else {
if (famAndQf.length == 1) {
LOG.warn("No column qualifier specified. Delete is the only mutation supported " + "over the whole column family.");
} else {
put.add(builder.clear().setRow(put.getRow()).setFamily(famAndQf[0]).setQualifier(famAndQf[1]).setTimestamp(put.getTimestamp()).setType(Cell.Type.Put).setValue(m.value != null ? getBytes(m.value) : HConstants.EMPTY_BYTE_ARRAY).build());
}
put.setDurability(m.writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
}
}
if (!delete.isEmpty()) {
table.delete(delete);
}
if (!put.isEmpty()) {
table.put(put);
}
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} catch (IllegalArgumentException e) {
LOG.warn(e.getMessage(), e);
throw new IllegalArgument(Throwables.getStackTraceAsString(e));
} finally {
closeTable(table);
}
}
use of org.apache.hadoop.hbase.thrift.generated.IllegalArgument in project hbase by apache.
the class ThriftUtilities method colDescFromThrift.
/**
* This utility method creates a new Hbase HColumnDescriptor object based on a
* Thrift ColumnDescriptor "struct".
*
* @param in Thrift ColumnDescriptor object
* @return ModifyableColumnFamilyDescriptor
* @throws IllegalArgument if the column name is empty
*/
public static ColumnFamilyDescriptor colDescFromThrift(ColumnDescriptor in) throws IllegalArgument {
Compression.Algorithm comp = Compression.getCompressionAlgorithmByName(in.compression.toLowerCase(Locale.ROOT));
BloomType bt = BloomType.valueOf(in.bloomFilterType);
if (in.name == null || !in.name.hasRemaining()) {
throw new IllegalArgument("column name is empty");
}
byte[] parsedName = CellUtil.parseColumn(Bytes.getBytes(in.name))[0];
return ColumnFamilyDescriptorBuilder.newBuilder(parsedName).setMaxVersions(in.maxVersions).setCompressionType(comp).setInMemory(in.inMemory).setBlockCacheEnabled(in.blockCacheEnabled).setTimeToLive(in.timeToLive > 0 ? in.timeToLive : Integer.MAX_VALUE).setBloomFilterType(bt).build();
}
use of org.apache.hadoop.hbase.thrift.generated.IllegalArgument in project hbase by apache.
the class ThriftHBaseServiceHandler method mutateRowsTs.
@Override
public void mutateRowsTs(ByteBuffer tableName, List<BatchMutation> rowBatches, long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError, IllegalArgument, TException {
List<Put> puts = new ArrayList<>();
List<Delete> deletes = new ArrayList<>();
CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
for (BatchMutation batch : rowBatches) {
byte[] row = getBytes(batch.row);
List<Mutation> mutations = batch.mutations;
Delete delete = new Delete(row);
addAttributes(delete, attributes);
Put put = new Put(row, timestamp);
addAttributes(put, attributes);
for (Mutation m : mutations) {
byte[][] famAndQf = CellUtil.parseColumn(getBytes(m.column));
if (m.isDelete) {
// no qualifier, family only.
if (famAndQf.length == 1) {
delete.addFamily(famAndQf[0], timestamp);
} else {
delete.addColumns(famAndQf[0], famAndQf[1], timestamp);
}
delete.setDurability(m.writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
} else {
if (famAndQf.length == 1) {
LOG.warn("No column qualifier specified. Delete is the only mutation supported " + "over the whole column family.");
}
if (famAndQf.length == 2) {
try {
put.add(builder.clear().setRow(put.getRow()).setFamily(famAndQf[0]).setQualifier(famAndQf[1]).setTimestamp(put.getTimestamp()).setType(Cell.Type.Put).setValue(m.value != null ? getBytes(m.value) : HConstants.EMPTY_BYTE_ARRAY).build());
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
} else {
throw new IllegalArgumentException("Invalid famAndQf provided.");
}
put.setDurability(m.writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
}
}
if (!delete.isEmpty()) {
deletes.add(delete);
}
if (!put.isEmpty()) {
puts.add(put);
}
}
Table table = null;
try {
table = getTable(tableName);
if (!puts.isEmpty()) {
table.put(puts);
}
if (!deletes.isEmpty()) {
table.delete(deletes);
}
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} catch (IllegalArgumentException e) {
LOG.warn(e.getMessage(), e);
throw new IllegalArgument(Throwables.getStackTraceAsString(e));
} finally {
closeTable(table);
}
}
use of org.apache.hadoop.hbase.thrift.generated.IllegalArgument in project hbase by apache.
the class ThriftHBaseServiceHandler method createTable.
@Override
public void createTable(ByteBuffer in_tableName, List<ColumnDescriptor> columnFamilies) throws IOError, IllegalArgument, AlreadyExists {
TableName tableName = getTableName(in_tableName);
try {
if (getAdmin().tableExists(tableName)) {
throw new AlreadyExists("table name already in use");
}
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
for (ColumnDescriptor col : columnFamilies) {
builder.setColumnFamily(ThriftUtilities.colDescFromThrift(col));
}
getAdmin().createTable(builder.build());
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} catch (IllegalArgumentException e) {
LOG.warn(e.getMessage(), e);
throw new IllegalArgument(Throwables.getStackTraceAsString(e));
}
}
use of org.apache.hadoop.hbase.thrift.generated.IllegalArgument in project hbase by apache.
the class ThriftHBaseServiceHandler method checkAndPut.
@Override
public boolean checkAndPut(ByteBuffer tableName, ByteBuffer row, ByteBuffer column, ByteBuffer value, Mutation mput, Map<ByteBuffer, ByteBuffer> attributes) throws IOError, IllegalArgument, TException {
Put put;
try {
put = new Put(getBytes(row), HConstants.LATEST_TIMESTAMP);
addAttributes(put, attributes);
byte[][] famAndQf = CellUtil.parseColumn(getBytes(mput.column));
put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(put.getRow()).setFamily(famAndQf[0]).setQualifier(famAndQf[1]).setTimestamp(put.getTimestamp()).setType(Cell.Type.Put).setValue(mput.value != null ? getBytes(mput.value) : HConstants.EMPTY_BYTE_ARRAY).build());
put.setDurability(mput.writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
} catch (IOException | IllegalArgumentException e) {
LOG.warn(e.getMessage(), e);
throw new IllegalArgument(Throwables.getStackTraceAsString(e));
}
Table table = null;
try {
table = getTable(tableName);
byte[][] famAndQf = CellUtil.parseColumn(getBytes(column));
Table.CheckAndMutateBuilder mutateBuilder = table.checkAndMutate(getBytes(row), famAndQf[0]).qualifier(famAndQf[1]);
if (value != null) {
return mutateBuilder.ifEquals(getBytes(value)).thenPut(put);
} else {
return mutateBuilder.ifNotExists().thenPut(put);
}
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} catch (IllegalArgumentException e) {
LOG.warn(e.getMessage(), e);
throw new IllegalArgument(Throwables.getStackTraceAsString(e));
} finally {
closeTable(table);
}
}
Aggregations