use of com.alibaba.jstorm.transactional.state.TransactionState in project jstorm by alibaba.
the class TransactionSpout method processCtrlEvent.
protected void processCtrlEvent(TopoMasterCtrlEvent event) {
//LOG.info("Received contronl event, {}", event.toString());
TransactionState state = null;
switch(event.getEventType()) {
case transactionInitState:
if (spoutStatus.equals(State.INIT)) {
if (event.hasEventValue()) {
state = (TransactionState) event.getEventValue().get(0);
}
initSpoutState(state);
spoutStatus = State.ACTIVE;
}
break;
case transactionRollback:
spoutStatus = State.ROLLBACK;
if (event.hasEventValue()) {
state = (TransactionState) event.getEventValue().get(0);
}
rollbackSpoutState(state);
LOG.info("Rollback to state, {}", state);
JStormUtils.sleepMs(5000);
outputCollector.flushInitBarrier();
break;
case transactionCommit:
BatchGroupId successBatchGroupId = (BatchGroupId) event.getEventValue().get(0);
removeSuccessBatch(successBatchGroupId.batchId);
//LOG.info("Commit Acked, current pending batchs: {}", committingBatches);
break;
case transactionStop:
spoutStatus = State.INACTIVE;
LOG.info("Stop, current pending batches: {}", committingBatches);
break;
case transactionStart:
spoutStatus = State.ACTIVE;
LOG.info("Start, current pending batches: {}", committingBatches);
break;
default:
LOG.warn("Received unsupported event, {}", event.toString());
break;
}
}
use of com.alibaba.jstorm.transactional.state.TransactionState 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.transactional.state.TransactionState in project jstorm by alibaba.
the class TransactionSpout method initSpoutState.
private void initSpoutState(TransactionState state) {
LOG.info("Initial state for spout: {}", state);
if (state == null) {
currState = new TransactionState(groupId, TransactionCommon.INIT_BATCH_ID, null, null);
} else {
currState = new TransactionState(state);
}
Object userState = Utils.maybe_deserialize((byte[]) currState.getUserCheckpoint());
spoutExecutor.initState(userState);
resetSpoutState();
}
use of com.alibaba.jstorm.transactional.state.TransactionState 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;
}
}
use of com.alibaba.jstorm.transactional.state.TransactionState in project jstorm by alibaba.
the class TransactionSpout method rollbackSpoutState.
private void rollbackSpoutState(TransactionState state) {
if (state != null) {
currState = new TransactionState(state);
Object userState = Utils.maybe_deserialize((byte[]) state.getUserCheckpoint());
spoutExecutor.rollBack(userState);
}
resetSpoutState();
}
Aggregations