Search in sources :

Example 1 with TopoMasterCtrlEvent

use of com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent in project jstorm by alibaba.

the class TransactionBolt method fail.

public void fail(BatchGroupId id) {
    // If any failure, send rollback request to TM 
    TopoMasterCtrlEvent event = new TopoMasterCtrlEvent(EventType.transactionRollback);
    event.addEventValue(id);
    outputCollector.emitDirectByDelegate(topologyMasterId, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(event));
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) Values(backtype.storm.tuple.Values)

Example 2 with TopoMasterCtrlEvent

use of com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent in project jstorm by alibaba.

the class TaskHeartbeatUpdater method process.

@Override
public void process(Object event) throws Exception {
    synchronized (_lock) {
        if (event instanceof UpdateConfigEvent) {
            update(((UpdateConfigEvent) event).getConf());
            return;
        }
        Tuple input = (Tuple) event;
        int sourceTask = input.getSourceTask();
        int uptime = (Integer) input.getValue(0);
        TaskStatus executorStatus = new TaskStatus();
        if (input.getValues().size() < 2) {
            // for compatibility
            executorStatus.setStatus(TaskStatus.RUN);
        } else {
            executorStatus.setStatus((byte) input.getValue(1));
        }
        boolean isSendSpoutTaskFinishStream = false;
        if (spoutsExecutorStatusMap.containsKey(sourceTask)) {
            spoutsExecutorStatusMap.put(sourceTask, executorStatus);
        } else if (boltsExecutorStatusMap.containsKey(sourceTask)) {
            boltsExecutorStatusMap.put(sourceTask, executorStatus);
        } else if (sourceTask != taskId) {
            LOG.warn("received invalid task heartbeat {}", input);
        }
        if (executorStatus.getStatus() == TaskStatus.INIT && spoutsExecutorStatusMap.get(sourceTask) != null) {
            boolean existInitStatusBolt = false;
            for (TaskStatus status : boltsExecutorStatusMap.values()) {
                if (status.getStatus() == TaskStatus.INIT || status.getStatus() == TaskStatus.SHUTDOWN) {
                    existInitStatusBolt = true;
                    break;
                }
            }
            if (!existInitStatusBolt)
                isSendSpoutTaskFinishStream = true;
        }
        if (client == null) {
            client = new NimbusClientWrapper();
            client.init(stormConf);
        }
        // Update the heartbeat for source task, but don't update it if task is initial status
        if (executorStatus.getStatus() != TaskStatus.INIT && uptime > 0) {
            TaskHeartbeat taskHb = taskHbMap.get().get(sourceTask);
            if (taskHb == null) {
                taskHb = new TaskHeartbeat(TimeUtils.current_time_secs(), uptime);
                TaskHeartbeat tmpTaskHb = taskHbMap.get().putIfAbsent(sourceTask, taskHb);
                if (tmpTaskHb != null) {
                    taskHb = tmpTaskHb;
                }
            }
            taskHb.set_time(TimeUtils.current_time_secs());
            taskHb.set_uptime(uptime);
        } else if (isSendSpoutTaskFinishStream) {
            TopoMasterCtrlEvent finishInitEvent = new TopoMasterCtrlEvent(TopoMasterCtrlEvent.EventType.topologyFinishInit);
            ((BoltCollector) (collector.getDelegate())).emitDirectCtrl(sourceTask, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(finishInitEvent));
            LOG.info("all bolts' task finish init operation, so tm will notify the spout task-{}", sourceTask);
        }
        // Send heartbeat info of all tasks to nimbus
        if (sourceTask == taskId) {
            uploadHB();
        }
    }
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) NimbusClientWrapper(backtype.storm.utils.NimbusClientWrapper) Values(backtype.storm.tuple.Values) UpdateConfigEvent(com.alibaba.jstorm.task.master.ctrlevent.UpdateConfigEvent) TaskStatus(com.alibaba.jstorm.task.TaskStatus) Tuple(backtype.storm.tuple.Tuple)

Example 3 with TopoMasterCtrlEvent

use of com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent 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)

Example 4 with TopoMasterCtrlEvent

use of com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent in project jstorm by alibaba.

the class SnapshotStateMaster method process.

public synchronized void process(Tuple tuple) {
    int taskId = tuple.getSourceTask();
    TopoMasterCtrlEvent event = (TopoMasterCtrlEvent) tuple.getValues().get(0);
    BatchGroupId batchGroupId = null;
    if (event.getEventValue() != null && event.getEventValue().size() > 0) {
        batchGroupId = (BatchGroupId) event.getEventValue().get(0);
    }
    SnapshotState snapshotState = null;
    // If batchGroupId == null, it is initState request
    if (batchGroupId != null) {
        snapshotState = topologySnapshotState.get(batchGroupId.groupId);
        if (snapshotState == null) {
            LOG.warn("unexpected event from task-{}, event={}", taskId, event.toString());
            ;
            return;
        }
    }
    LOG.debug("Received control event from task-{}, event={}", taskId, event);
    boolean isFinished = false;
    switch(event.getEventType()) {
        case transactionInitState:
            for (Entry<Integer, SnapshotState> entry : topologySnapshotState.entrySet()) {
                TransactionState state = entry.getValue().getInitState(taskId);
                int groupId = entry.getKey();
                if (state != null) {
                    TopoMasterCtrlEvent initStateResp = new TopoMasterCtrlEvent(EventType.transactionInitState);
                    initStateResp.addEventValue(state);
                    ((BoltCollector) (outputCollector.getDelegate())).emitDirectCtrl(taskId, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(initStateResp));
                }
            }
            break;
        case transactionCommit:
            TransactionState commitState = (TransactionState) event.getEventValue().get(1);
            isFinished = snapshotState.commit(batchGroupId.batchId, taskId, commitState);
            break;
        case transactionAck:
            isFinished = snapshotState.ackEndBolt(batchGroupId.batchId, taskId);
            break;
        case transactionRollback:
            // If receiving rollback request, TM will rollback all tasks which are on the same stream as this task
            stopAndRollback(batchGroupId.groupId, snapshotState.rollback());
            break;
        default:
            LOG.warn("unexpected event type from task-{}, event={}", taskId, event.toString());
            break;
    }
    if (isFinished) {
        finishSnapshotStateCommit(batchGroupId, snapshotState);
    }
    LOG.debug("snapshotState: {}", snapshotState);
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) BatchGroupId(com.alibaba.jstorm.transactional.BatchGroupId) Values(backtype.storm.tuple.Values) BoltCollector(com.alibaba.jstorm.task.execute.BoltCollector)

Example 5 with TopoMasterCtrlEvent

use of com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent in project jstorm by alibaba.

the class TransactionBolt method processTransactionEvent.

protected void processTransactionEvent(Tuple input) {
    TopoMasterCtrlEvent event = (TopoMasterCtrlEvent) input.getValues().get(0);
    TransactionState state = null;
    switch(event.getEventType()) {
        case transactionInitState:
            state = (TransactionState) event.getEventValue().get(0);
            initState(state);
            boltStatus = State.ACTIVE;
            break;
        case transactionRollback:
            boltStatus = State.ROLLBACK;
            state = (TransactionState) event.getEventValue().get(0);
            rollback(state);
            break;
        case transactionCommit:
            BatchGroupId batchGroupId = (BatchGroupId) event.getEventValue().get(0);
            ackCommit(batchGroupId);
            break;
        default:
            LOG.warn("Received unexpected transaction event, {}" + event.toString());
            break;
    }
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) TransactionState(com.alibaba.jstorm.transactional.state.TransactionState) BatchGroupId(com.alibaba.jstorm.transactional.BatchGroupId)

Aggregations

TopoMasterCtrlEvent (com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent)13 Values (backtype.storm.tuple.Values)11 BoltCollector (com.alibaba.jstorm.task.execute.BoltCollector)4 BatchGroupId (com.alibaba.jstorm.transactional.BatchGroupId)4 Tuple (backtype.storm.tuple.Tuple)2 TransactionState (com.alibaba.jstorm.transactional.state.TransactionState)2 HashSet (java.util.HashSet)2 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)1 NimbusClientWrapper (backtype.storm.utils.NimbusClientWrapper)1 CtrlMsgSpout (com.alibaba.jstorm.client.spout.CtrlMsgSpout)1 ICtrlMsgSpout (com.alibaba.jstorm.client.spout.ICtrlMsgSpout)1 TaskStatus (com.alibaba.jstorm.task.TaskStatus)1 TupleInfo (com.alibaba.jstorm.task.comm.TupleInfo)1 AckSpoutMsg (com.alibaba.jstorm.task.execute.spout.AckSpoutMsg)1 FailSpoutMsg (com.alibaba.jstorm.task.execute.spout.FailSpoutMsg)1 UpdateConfigEvent (com.alibaba.jstorm.task.master.ctrlevent.UpdateConfigEvent)1 BatchInfo (com.alibaba.jstorm.transactional.spout.TransactionSpoutOutputCollector.BatchInfo)1 RotatingMap (com.alibaba.jstorm.utils.RotatingMap)1 Map (java.util.Map)1