Search in sources :

Example 6 with TopoMasterCtrlEvent

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

the class TransactionBolt method ackBatch.

private void ackBatch(BatchGroupId batchGroupId) {
    TopoMasterCtrlEvent event = new TopoMasterCtrlEvent(EventType.transactionAck);
    event.addEventValue(batchGroupId);
    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 7 with TopoMasterCtrlEvent

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

the class TransactionSpout method startInitState.

protected void startInitState() {
    LOG.info("Start to retrieve the initial state from topology master");
    // retrieve state from topology master
    TopoMasterCtrlEvent event = new TopoMasterCtrlEvent(EventType.transactionInitState);
    outputCollector.emitDirectByDelegate(topologyMasterId, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, new Values(event), null);
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) Values(backtype.storm.tuple.Values)

Example 8 with TopoMasterCtrlEvent

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

the class SpoutExecutors method processTupleEvent.

private Runnable processTupleEvent(Tuple event) {
    Runnable runnable = null;
    Tuple tuple = (Tuple) event;
    if (event.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID)) {
        TopoMasterCtrlEvent ctrlEvent = (TopoMasterCtrlEvent) tuple.getValueByField("ctrlEvent");
        if (ctrlEvent.isTransactionEvent()) {
            if (spout instanceof ICtrlMsgSpout) {
                runnable = new CtrlMsgSpout((ICtrlMsgSpout) spout, ctrlEvent);
            }
        } else if (ctrlEvent.isFinishInitEvent()) {
            LOG.info("spout task-{} received topology finish init operation message", taskId);
            taskHbTrigger.updateExecutorStatus(TaskStatus.RUN);
            this.checkTopologyFinishInit = true;
        } else {
            LOG.warn("Received unexpected control event, {}", ctrlEvent);
        }
    } else if (event.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID)) {
        this.metricsReporter.updateMetricMeta((Map<String, Long>) tuple.getValue(0));
    } else {
        Object id = tuple.getValue(0);
        Object obj = pending.remove((Long) id);
        if (obj == null) {
            if (JStormDebugger.isDebug(id)) {
                LOG.info("Pending map no entry:" + id);
            }
            runnable = null;
        } else {
            TupleInfo tupleInfo = (TupleInfo) obj;
            String stream_id = tuple.getSourceStreamId();
            if (stream_id.equals(Acker.ACKER_ACK_STREAM_ID)) {
                runnable = new AckSpoutMsg(id, spout, tuple, tupleInfo, task_stats);
            } else if (stream_id.equals(Acker.ACKER_FAIL_STREAM_ID)) {
                runnable = new FailSpoutMsg(id, spout, tupleInfo, task_stats);
            } else {
                LOG.warn("Receive one unknown source Tuple " + idStr);
                runnable = null;
            }
        }
        task_stats.recv_tuple(tuple.getSourceComponent(), tuple.getSourceStreamId());
    }
    return runnable;
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) TupleInfo(com.alibaba.jstorm.task.comm.TupleInfo) AckSpoutMsg(com.alibaba.jstorm.task.execute.spout.AckSpoutMsg) ICtrlMsgSpout(com.alibaba.jstorm.client.spout.ICtrlMsgSpout) CtrlMsgSpout(com.alibaba.jstorm.client.spout.CtrlMsgSpout) ICtrlMsgSpout(com.alibaba.jstorm.client.spout.ICtrlMsgSpout) FailSpoutMsg(com.alibaba.jstorm.task.execute.spout.FailSpoutMsg) Map(java.util.Map) RotatingMap(com.alibaba.jstorm.utils.RotatingMap) Tuple(backtype.storm.tuple.Tuple)

Example 9 with TopoMasterCtrlEvent

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

the class SnapshotStateMaster method sendRollbackRequest.

private void sendRollbackRequest(int groupId, Map<Integer, TransactionState> tasksToStates) {
    // Rollback for stateful tasks
    Iterator<Integer> iter = tasksToStates.keySet().iterator();
    while (iter.hasNext()) {
        int taskId = iter.next();
        TransactionState state = tasksToStates.get(taskId) != null ? tasksToStates.get(taskId) : new TransactionState(groupId, 0, null, null);
        TopoMasterCtrlEvent rollbackRequest = new TopoMasterCtrlEvent(EventType.transactionRollback);
        rollbackRequest.addEventValue(state);
        ((BoltCollector) (outputCollector.getDelegate())).emitDirectCtrl(taskId, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(rollbackRequest));
    }
    LOG.info("Send rollback request to group:{}, tasks:{}", groupIdToNames.get(groupId), tasksToStates.keySet());
    // Rollback for non-stateful tasks
    SnapshotState snapshot = topologySnapshotState.get(groupId);
    TransactionState state = new TransactionState(groupId, snapshot.getLastSuccessfulBatchId(), null, null);
    TopoMasterCtrlEvent rollbackRequest = new TopoMasterCtrlEvent(EventType.transactionRollback);
    rollbackRequest.addEventValue(state);
    for (Integer nonStatefulTaskId : snapshot.getNonStatefulTasks()) {
        ((BoltCollector) (outputCollector.getDelegate())).emitDirectCtrl(nonStatefulTaskId, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(rollbackRequest));
    }
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) Values(backtype.storm.tuple.Values) BoltCollector(com.alibaba.jstorm.task.execute.BoltCollector)

Example 10 with TopoMasterCtrlEvent

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

the class SnapshotStateMaster method stopAndRollback.

private void stopAndRollback(final int groupId, final Map<Integer, TransactionState> tasksToStates) {
    List<String> spoutNames = groupIdToNames.get(groupId);
    for (String spoutName : spoutNames) {
        for (int taskId : context.getComponentTasks(spoutName)) {
            TopoMasterCtrlEvent stop = new TopoMasterCtrlEvent(EventType.transactionStop);
            stop.addEventValue(groupId);
            ((BoltCollector) (outputCollector.getDelegate())).emitDirectCtrl(taskId, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(stop));
        }
    }
    LOG.info("Stop spouts={}, tasks={}", spoutNames, context.getComponentsTasks(new HashSet<String>(spoutNames)));
    scheduledService.schedule(new Runnable() {

        @Override
        public void run() {
            sendRollbackRequest(groupId, tasksToStates);
        }
    }, 10, TimeUnit.SECONDS);
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) Values(backtype.storm.tuple.Values) BoltCollector(com.alibaba.jstorm.task.execute.BoltCollector) HashSet(java.util.HashSet)

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