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