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());
}
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));
}
}
}
}
}
}
Aggregations