Search in sources :

Example 6 with PutBuilder

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

the class HBaseMessageTable method persist.

@Override
protected void persist(Iterator<RawMessageTableEntry> entries) throws IOException {
    List<Put> batchPuts = new ArrayList<>();
    while (entries.hasNext()) {
        RawMessageTableEntry entry = entries.next();
        PutBuilder putBuilder = tableUtil.buildPut(rowKeyDistributor.getDistributedKey(entry.getKey()));
        if (entry.getTxPtr() != null) {
            putBuilder.add(columnFamily, TX_COL, entry.getTxPtr());
        }
        if (entry.getPayload() != null) {
            putBuilder.add(columnFamily, PAYLOAD_COL, entry.getPayload());
        }
        batchPuts.add(putBuilder.build());
    }
    try {
        if (!batchPuts.isEmpty()) {
            hTable.put(batchPuts);
            if (!hTable.isAutoFlush()) {
                hTable.flushCommits();
            }
        }
    } catch (IOException e) {
        throw exceptionHandler.handle(e);
    }
}
Also used : PutBuilder(co.cask.cdap.data2.util.hbase.PutBuilder) ArrayList(java.util.ArrayList) RawMessageTableEntry(co.cask.cdap.messaging.store.RawMessageTableEntry) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put)

Aggregations

PutBuilder (co.cask.cdap.data2.util.hbase.PutBuilder)6 IOException (java.io.IOException)5 Put (org.apache.hadoop.hbase.client.Put)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NavigableMap (java.util.NavigableMap)3 DataSetException (co.cask.cdap.api.dataset.DataSetException)2 SortedMap (java.util.SortedMap)2 Result (org.apache.hadoop.hbase.client.Result)2 TopicAlreadyExistsException (co.cask.cdap.api.messaging.TopicAlreadyExistsException)1 IncrementValue (co.cask.cdap.data2.dataset2.lib.table.IncrementValue)1 PutValue (co.cask.cdap.data2.dataset2.lib.table.PutValue)1 Update (co.cask.cdap.data2.dataset2.lib.table.Update)1 IncrementBuilder (co.cask.cdap.data2.util.hbase.IncrementBuilder)1 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)1 RawMessageTableEntry (co.cask.cdap.messaging.store.RawMessageTableEntry)1 TopicId (co.cask.cdap.proto.id.TopicId)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TreeMap (java.util.TreeMap)1 Get (org.apache.hadoop.hbase.client.Get)1