Search in sources :

Example 1 with COMMIT

use of org.apache.storm.spout.CheckPointState.Action.COMMIT in project storm by apache.

the class StatefulBoltExecutor method handleCheckpoint.

@Override
protected void handleCheckpoint(Tuple checkpointTuple, Action action, long txid) {
    LOG.debug("handleCheckPoint with tuple {}, action {}, txid {}", checkpointTuple, action, txid);
    if (action == PREPARE) {
        if (boltInitialized) {
            bolt.prePrepare(txid);
            state.prepareCommit(txid);
            preparedTuples.addAll(collector.ackedTuples());
        } else {
            /*
                 * May be the task restarted in the middle and the state needs be initialized.
                 * Fail fast and trigger recovery.
                  */
            LOG.debug("Failing checkpointTuple, PREPARE received when bolt state is not initialized.");
            collector.fail(checkpointTuple);
            return;
        }
    } else if (action == COMMIT) {
        bolt.preCommit(txid);
        state.commit(txid);
        ack(preparedTuples);
    } else if (action == ROLLBACK) {
        bolt.preRollback();
        state.rollback();
        fail(preparedTuples);
        fail(collector.ackedTuples());
    } else if (action == INITSTATE) {
        if (!boltInitialized) {
            bolt.initState((T) state);
            boltInitialized = true;
            LOG.debug("{} pending tuples to process", pendingTuples.size());
            for (Tuple tuple : pendingTuples) {
                doExecute(tuple);
            }
            pendingTuples.clear();
        } else {
            LOG.debug("Bolt state is already initialized, ignoring tuple {}, action {}, txid {}", checkpointTuple, action, txid);
        }
    }
    collector.emit(CheckpointSpout.CHECKPOINT_STREAM_ID, checkpointTuple, new Values(txid, action));
    collector.delegate.ack(checkpointTuple);
}
Also used : COMMIT(org.apache.storm.spout.CheckPointState.Action.COMMIT) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple)

Aggregations

COMMIT (org.apache.storm.spout.CheckPointState.Action.COMMIT)1 Tuple (org.apache.storm.tuple.Tuple)1 Values (org.apache.storm.tuple.Values)1