Search in sources :

Example 1 with IllegalArgument

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);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) CellBuilder(org.apache.hadoop.hbase.CellBuilder) BatchMutation(org.apache.hadoop.hbase.thrift.generated.BatchMutation) Mutation(org.apache.hadoop.hbase.thrift.generated.Mutation) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) IllegalArgument(org.apache.hadoop.hbase.thrift.generated.IllegalArgument) Put(org.apache.hadoop.hbase.client.Put)

Example 2 with IllegalArgument

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();
}
Also used : Compression(org.apache.hadoop.hbase.io.compress.Compression) BloomType(org.apache.hadoop.hbase.regionserver.BloomType) IllegalArgument(org.apache.hadoop.hbase.thrift.generated.IllegalArgument)

Example 3 with IllegalArgument

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);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) ArrayList(java.util.ArrayList) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) CellBuilder(org.apache.hadoop.hbase.CellBuilder) BatchMutation(org.apache.hadoop.hbase.thrift.generated.BatchMutation) Mutation(org.apache.hadoop.hbase.thrift.generated.Mutation) BatchMutation(org.apache.hadoop.hbase.thrift.generated.BatchMutation) IllegalArgument(org.apache.hadoop.hbase.thrift.generated.IllegalArgument)

Example 4 with IllegalArgument

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));
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ColumnDescriptor(org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) AlreadyExists(org.apache.hadoop.hbase.thrift.generated.AlreadyExists) IllegalArgument(org.apache.hadoop.hbase.thrift.generated.IllegalArgument)

Example 5 with IllegalArgument

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);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) IllegalArgument(org.apache.hadoop.hbase.thrift.generated.IllegalArgument) Put(org.apache.hadoop.hbase.client.Put)

Aggregations

IllegalArgument (org.apache.hadoop.hbase.thrift.generated.IllegalArgument)5 IOException (java.io.IOException)4 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 Put (org.apache.hadoop.hbase.client.Put)3 Table (org.apache.hadoop.hbase.client.Table)3 CellBuilder (org.apache.hadoop.hbase.CellBuilder)2 Delete (org.apache.hadoop.hbase.client.Delete)2 BatchMutation (org.apache.hadoop.hbase.thrift.generated.BatchMutation)2 Mutation (org.apache.hadoop.hbase.thrift.generated.Mutation)2 ArrayList (java.util.ArrayList)1 TableName (org.apache.hadoop.hbase.TableName)1 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)1 Compression (org.apache.hadoop.hbase.io.compress.Compression)1 BloomType (org.apache.hadoop.hbase.regionserver.BloomType)1 AlreadyExists (org.apache.hadoop.hbase.thrift.generated.AlreadyExists)1 ColumnDescriptor (org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor)1