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));
}
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();
}
}
}
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);
}
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);
}
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;
}
}
Aggregations