Search in sources :

Example 1 with DeleteBuilder

use of co.cask.cdap.data2.util.hbase.DeleteBuilder in project cdap by caskdata.

the class HBaseMetricsTable method delete.

@Override
public void delete(byte[] row, byte[][] columns) {
    byte[] distributedKey = createDistributedRowKey(row);
    DeleteBuilder delete = tableUtil.buildDelete(distributedKey);
    for (byte[] column : columns) {
        delete.deleteColumns(columnFamily, column);
    }
    try {
        hTable.delete(delete.build());
    } catch (IOException e) {
        throw new DataSetException("Delete failed on table " + tableId, e);
    }
}
Also used : DataSetException(co.cask.cdap.api.dataset.DataSetException) IOException(java.io.IOException) DeleteBuilder(co.cask.cdap.data2.util.hbase.DeleteBuilder)

Example 2 with DeleteBuilder

use of co.cask.cdap.data2.util.hbase.DeleteBuilder in project cdap by caskdata.

the class HBaseTable method undo.

@Override
protected void undo(NavigableMap<byte[], NavigableMap<byte[], Update>> persisted) throws Exception {
    if (persisted.isEmpty()) {
        return;
    }
    // NOTE: we use Delete with the write pointer as the specific version to delete.
    List<Delete> deletes = Lists.newArrayList();
    for (Map.Entry<byte[], NavigableMap<byte[], Update>> row : persisted.entrySet()) {
        DeleteBuilder delete = tableUtil.buildDelete(row.getKey());
        delete.setAttribute(TX_MAX_LIFETIME_MILLIS_KEY, txMaxLifetimeMillis);
        for (Map.Entry<byte[], Update> column : row.getValue().entrySet()) {
            // we want support tx and non-tx modes
            if (tx != null) {
                delete.setAttribute(TxConstants.TX_ROLLBACK_ATTRIBUTE_KEY, new byte[0]);
                // TODO: hijacking timestamp... bad
                delete.deleteColumn(columnFamily, column.getKey(), tx.getWritePointer());
            } else {
                delete.deleteColumns(columnFamily, column.getKey());
            }
        }
        deletes.add(delete.build());
    }
    if (!deletes.isEmpty()) {
        hbaseDelete(deletes);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) NavigableMap(java.util.NavigableMap) Update(co.cask.cdap.data2.dataset2.lib.table.Update) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NavigableMap(java.util.NavigableMap) DeleteBuilder(co.cask.cdap.data2.util.hbase.DeleteBuilder)

Aggregations

DeleteBuilder (co.cask.cdap.data2.util.hbase.DeleteBuilder)2 DataSetException (co.cask.cdap.api.dataset.DataSetException)1 Update (co.cask.cdap.data2.dataset2.lib.table.Update)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 Delete (org.apache.hadoop.hbase.client.Delete)1