Search in sources :

Example 11 with TopoMasterCtrlEvent

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

the class SnapshotStateMaster method finishSnapshotStateCommit.

private void finishSnapshotStateCommit(BatchGroupId batchGroupId, SnapshotState snapshotState) {
    Set<Integer> statefulTasks = new HashSet<Integer>();
    statefulTasks.addAll(snapshotState.getSpoutTasks());
    TopoMasterCtrlEvent resp = null;
    boolean isCommitSuccess = false;
    if (batchGroupId.batchId != TransactionCommon.INIT_BATCH_ID) {
        if (snapshotState.isActive()) {
            resp = new TopoMasterCtrlEvent(EventType.transactionCommit);
            resp.addEventValue(batchGroupId);
            statefulTasks.addAll(snapshotState.getStatefulTasks());
            snapshotState.successBatch(batchGroupId.batchId);
            // Try to persist the topology snapshot state. But if any failure happened, just continue.
            try {
                isCommitSuccess = stateOperator.commitState(topologyName, batchGroupId.groupId, topologySnapshotState);
                if (!isCommitSuccess) {
                    LOG.warn("Failed to commit topology state for batch-{}", batchGroupId);
                }
            } catch (Exception e) {
                LOG.warn("Got exception, when committing topology state for batch-{}, {}", batchGroupId, e);
            }
        }
    } else {
        snapshotState.setActive();
        resp = new TopoMasterCtrlEvent(EventType.transactionStart);
        snapshotState.successBatch(batchGroupId.batchId);
        isCommitSuccess = true;
    }
    if (isCommitSuccess) {
        // Ack the init or commit request from spout and stateful bolt
        LOG.debug("Send ack to spouts-{}, event={}", statefulTasks, resp);
        for (Integer spoutTask : statefulTasks) {
            ((BoltCollector) (outputCollector.getDelegate())).emitDirectCtrl(spoutTask, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(resp));
        }
    }
    long nextPendingSuccessBatch = snapshotState.getPendingSuccessBatch();
    if (nextPendingSuccessBatch != -1) {
        LOG.info("Try to commit a pending successful batch-{}", nextPendingSuccessBatch);
        finishSnapshotStateCommit(new BatchGroupId(batchGroupId.groupId, nextPendingSuccessBatch), snapshotState);
    }
}
Also used : TopoMasterCtrlEvent(com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent) BatchGroupId(com.alibaba.jstorm.transactional.BatchGroupId) Values(backtype.storm.tuple.Values) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) BoltCollector(com.alibaba.jstorm.task.execute.BoltCollector) HashSet(java.util.HashSet)

Example 12 with TopoMasterCtrlEvent

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

the class TransactionBolt method startInitState.

protected void startInitState() {
    LOG.info("Start to retrieve initialize state from topology master");
    // retrieve state from topology master
    TopoMasterCtrlEvent event = new TopoMasterCtrlEvent(EventType.transactionInitState);
    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 13 with TopoMasterCtrlEvent

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

the class TransactionStatefulBolt method persistCommit.

protected void persistCommit(BatchTracker committingBatch) {
    TopoMasterCtrlEvent event = new TopoMasterCtrlEvent(EventType.transactionCommit);
    event.addEventValue(committingBatch.getBatchGroupId());
    byte[] persistData = (byte[]) committingBatch.getState().getUserCheckpoint();
    Object persistKey = null;
    try {
        persistKey = boltExecutor.commit(committingBatch.getBatchGroupId(), Utils.maybe_deserialize(persistData));
    } catch (Exception e) {
        LOG.warn("Failed to persist user checkpoint for batch-{}", committingBatch.getBatchGroupId());
        return;
    }
    if (persistKey == TransactionCommon.COMMIT_FAIL) {
        LOG.warn("Failed to persist user checkpoint for batch-{}", committingBatch.getBatchGroupId());
        return;
    }
    committingBatch.getState().setUserCheckpoint(Utils.trySerialize(persistKey));
    event.addEventValue(committingBatch.getState());
    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)

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