Search in sources :

Example 1 with HTableConnector

use of backtype.storm.contrib.hbase.utils.HTableConnector in project storm-hbase by jrkinley.

the class HBaseBolt method prepare.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("rawtypes")
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    try {
        this.connector = new HTableConnector(conf);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    LOG.info("Preparing HBaseBolt for table: " + this.conf.getTableName());
}
Also used : HTableConnector(backtype.storm.contrib.hbase.utils.HTableConnector) IOException(java.io.IOException)

Example 2 with HTableConnector

use of backtype.storm.contrib.hbase.utils.HTableConnector in project storm-hbase by jrkinley.

the class HBaseCountersBatchBolt method finishBatch.

/**
 * {@inheritDoc}
 */
@Override
public void finishBatch() {
    try {
        connector = new HTableConnector(conf);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Finishing tx: " + attempt.getTransactionId());
        LOG.debug(String.format("Updating idempotent counters for %d rows in table '%s'", counters.size(), conf.getTableName()));
    }
    for (Increment inc : counters.values()) {
        for (Entry<byte[], NavigableMap<byte[], Long>> e : inc.getFamilyMap().entrySet()) {
            for (Entry<byte[], Long> c : e.getValue().entrySet()) {
                // Get counters latest txid from table
                byte[] txidCQ = txidQualifier(c.getKey());
                BigInteger latestTxid = getLatestTxid(inc.getRow(), e.getKey(), txidCQ);
                long counter = c.getValue();
                if (latestTxid == null || !latestTxid.equals(attempt.getTransactionId())) {
                    // txids are different so safe to increment counter
                    try {
                        counter = connector.getTable().incrementColumnValue(inc.getRow(), e.getKey(), c.getKey(), c.getValue(), conf.isWriteToWAL());
                    } catch (IOException ex) {
                        throw new RuntimeException(String.format("Unable to increment counter: %s, %s, %s", Bytes.toString(inc.getRow()), Bytes.toString(e.getKey()), Bytes.toString(c.getKey())), ex);
                    }
                    putLatestTxid(inc.getRow(), e.getKey(), txidCQ);
                    collector.emit(new Values(inc.getRow(), e.getKey(), c.getKey(), counter));
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(String.format("txids for counter %s, %s, %s are different [%d, %d], incrementing", Bytes.toString(inc.getRow()), Bytes.toString(e.getKey()), Bytes.toString(c.getKey()), latestTxid, attempt.getTransactionId()));
                    }
                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(String.format("txids for counter %s, %s, %s are the same [%d], skipping", Bytes.toString(inc.getRow()), Bytes.toString(e.getKey()), Bytes.toString(c.getKey()), latestTxid));
                    }
                }
            }
        }
    }
}
Also used : HTableConnector(backtype.storm.contrib.hbase.utils.HTableConnector) NavigableMap(java.util.NavigableMap) Increment(org.apache.hadoop.hbase.client.Increment) Values(backtype.storm.tuple.Values) BigInteger(java.math.BigInteger) IOException(java.io.IOException)

Aggregations

HTableConnector (backtype.storm.contrib.hbase.utils.HTableConnector)2 IOException (java.io.IOException)2 Values (backtype.storm.tuple.Values)1 BigInteger (java.math.BigInteger)1 NavigableMap (java.util.NavigableMap)1 Increment (org.apache.hadoop.hbase.client.Increment)1