Search in sources :

Example 1 with BatchGroupId

use of com.alibaba.jstorm.transactional.BatchGroupId in project jstorm by alibaba.

the class TransactionBolt method initState.

protected void initState(TransactionState state) {
    BatchGroupId batchGroupId = state.getCurrBatchGroupId();
    lastSuccessfulBatch.put(batchGroupId.groupId, batchGroupId.batchId);
    LOG.info("Init: state={}, lastSuccessfulBatch={}", state, lastSuccessfulBatch);
}
Also used : BatchGroupId(com.alibaba.jstorm.transactional.BatchGroupId)

Example 2 with BatchGroupId

use of com.alibaba.jstorm.transactional.BatchGroupId in project jstorm by alibaba.

the class TransactionBolt method rollback.

protected void rollback(TransactionState state) {
    BatchGroupId batchGroupId = state.getCurrBatchGroupId();
    LOG.info("Start to rollback to batch-{}, currentBatchStateus={}", batchGroupId, currentBatchStatusInfo());
    lastSuccessfulBatch.put(batchGroupId.groupId, batchGroupId.batchId);
    cleanupBuffer(state.getCurrBatchGroupId().groupId);
}
Also used : BatchGroupId(com.alibaba.jstorm.transactional.BatchGroupId)

Example 3 with BatchGroupId

use of com.alibaba.jstorm.transactional.BatchGroupId in project jstorm by alibaba.

the class TransactionBolt method finishCurrentBatch.

private void finishCurrentBatch() {
    BatchGroupId batchGroupId = currentBatchTracker.bactchGroupId;
    if (batchGroupId.batchId == TransactionCommon.INIT_BATCH_ID) {
        LOG.info("Received all init events");
        cleanupBuffer(batchGroupId.groupId);
        boltStatus = State.ACTIVE;
    } else {
        commit();
        lastSuccessfulBatch.put(batchGroupId.groupId, batchGroupId.batchId);
    }
    if (downstreamTasks.size() == 0) {
        ackBatch(batchGroupId);
    } else {
        outputCollector.flushBarrier();
    }
    removeProcessingBatch(batchGroupId);
    currentBatchTracker = null;
    LOG.debug("finishCurrentBatch, {}", currentBatchStatusInfo());
    List<Tuple> goingtoProcessBatch = batchCache.getNextPendingTuples(lastSuccessfulBatch);
    if (goingtoProcessBatch != null) {
        BatchGroupId nextGroupBatchId = new BatchGroupId(batchGroupId.groupId, batchGroupId.batchId + 1);
        //LOG.info("Get pending batch-{} which is going to be processed. size={}", nextGroupBatchId, goingtoProcessBatch.size());
        processBatch(nextGroupBatchId, goingtoProcessBatch);
    }
}
Also used : BatchGroupId(com.alibaba.jstorm.transactional.BatchGroupId) Tuple(backtype.storm.tuple.Tuple)

Example 4 with BatchGroupId

use of com.alibaba.jstorm.transactional.BatchGroupId in project jstorm by alibaba.

the class TransactionSpout method processCtrlEvent.

protected void processCtrlEvent(TopoMasterCtrlEvent event) {
    //LOG.info("Received contronl event, {}", event.toString());
    TransactionState state = null;
    switch(event.getEventType()) {
        case transactionInitState:
            if (spoutStatus.equals(State.INIT)) {
                if (event.hasEventValue()) {
                    state = (TransactionState) event.getEventValue().get(0);
                }
                initSpoutState(state);
                spoutStatus = State.ACTIVE;
            }
            break;
        case transactionRollback:
            spoutStatus = State.ROLLBACK;
            if (event.hasEventValue()) {
                state = (TransactionState) event.getEventValue().get(0);
            }
            rollbackSpoutState(state);
            LOG.info("Rollback to state, {}", state);
            JStormUtils.sleepMs(5000);
            outputCollector.flushInitBarrier();
            break;
        case transactionCommit:
            BatchGroupId successBatchGroupId = (BatchGroupId) event.getEventValue().get(0);
            removeSuccessBatch(successBatchGroupId.batchId);
            //LOG.info("Commit Acked, current pending batchs: {}", committingBatches);
            break;
        case transactionStop:
            spoutStatus = State.INACTIVE;
            LOG.info("Stop, current pending batches: {}", committingBatches);
            break;
        case transactionStart:
            spoutStatus = State.ACTIVE;
            LOG.info("Start, current pending batches: {}", committingBatches);
            break;
        default:
            LOG.warn("Received unsupported event, {}", event.toString());
            break;
    }
}
Also used : TransactionState(com.alibaba.jstorm.transactional.state.TransactionState) BatchGroupId(com.alibaba.jstorm.transactional.BatchGroupId)

Example 5 with BatchGroupId

use of com.alibaba.jstorm.transactional.BatchGroupId 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

BatchGroupId (com.alibaba.jstorm.transactional.BatchGroupId)18 Values (backtype.storm.tuple.Values)6 ArrayList (java.util.ArrayList)5 TopoMasterCtrlEvent (com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent)4 BatchSnapshot (com.alibaba.jstorm.transactional.BatchSnapshot)3 TransactionState (com.alibaba.jstorm.transactional.state.TransactionState)3 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)2 ICollectorCallback (backtype.storm.task.ICollectorCallback)2 BoltCollector (com.alibaba.jstorm.task.execute.BoltCollector)2 Tuple (backtype.storm.tuple.Tuple)1 CountValue (com.alibaba.jstorm.transactional.bolt.TransactionBolt.CountValue)1 BatchInfo (com.alibaba.jstorm.transactional.spout.TransactionSpoutOutputCollector.BatchInfo)1 Pair (com.alibaba.jstorm.utils.Pair)1 HashSet (java.util.HashSet)1