Search in sources :

Example 1 with BatchInfo

use of com.alibaba.jstorm.transactional.spout.TransactionSpoutOutputCollector.BatchInfo in project jstorm by alibaba.

the class TransactionSpout method commit.

protected void commit() {
    if (isActive() == false) {
        // If spout has not finished initialization or is inactive, just return.
        return;
    }
    Object userState = spoutExecutor.finishBatch();
    BatchInfo batchInfo = outputCollector.flushBarrier();
    BatchGroupId id = new BatchGroupId(groupId, batchInfo.batchId);
    Object commitState = null;
    try {
        commitState = spoutExecutor.commit(id, userState);
    } catch (Exception e) {
        LOG.warn("Failed to commit spout state for batch-{}, {}", id, e);
        return;
    }
    if (commitState == TransactionCommon.COMMIT_FAIL) {
        LOG.warn("Failed to commit spout state for batch-{}", id);
        return;
    }
    currState.setBatchId(batchInfo.batchId);
    currState.setUserCheckpoint(Utils.trySerialize(commitState));
    committingBatches.add(batchInfo.batchId);
    updateMaxPendingFlag();
    TopoMasterCtrlEvent event = new TopoMasterCtrlEvent(EventType.transactionCommit);
    TransactionState state = new TransactionState(currState);
    event.addEventValue(state.getCurrBatchGroupId());
    event.addEventValue(state);
    outputCollector.emitDirectByDelegate(topologyMasterId, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, new Values(event), null);
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) TransactionState(com.alibaba.jstorm.transactional.state.TransactionState) BatchGroupId(com.alibaba.jstorm.transactional.BatchGroupId) Values(backtype.storm.tuple.Values) BatchInfo(com.alibaba.jstorm.transactional.spout.TransactionSpoutOutputCollector.BatchInfo)

Aggregations

Values (backtype.storm.tuple.Values)1 TopoMasterCtrlEvent (com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent)1 BatchGroupId (com.alibaba.jstorm.transactional.BatchGroupId)1 BatchInfo (com.alibaba.jstorm.transactional.spout.TransactionSpoutOutputCollector.BatchInfo)1 TransactionState (com.alibaba.jstorm.transactional.state.TransactionState)1