use of io.seata.tm.api.GlobalTransaction in project seata by seata.
the class DbAndReportTcStateLogStore method reportTransactionFinished.
protected void reportTransactionFinished(StateMachineInstance machineInstance, ProcessContext context) {
if (sagaTransactionalTemplate != null) {
try {
GlobalTransaction globalTransaction = getGlobalTransaction(machineInstance, context);
if (globalTransaction == null) {
throw new EngineExecutionException("Global transaction is not exists", FrameworkErrorCode.ObjectNotExists);
}
GlobalStatus globalStatus;
if (ExecutionStatus.SU.equals(machineInstance.getStatus()) && machineInstance.getCompensationStatus() == null) {
globalStatus = GlobalStatus.Committed;
} else if (ExecutionStatus.SU.equals(machineInstance.getCompensationStatus())) {
globalStatus = GlobalStatus.Rollbacked;
} else if (ExecutionStatus.FA.equals(machineInstance.getCompensationStatus()) || ExecutionStatus.UN.equals(machineInstance.getCompensationStatus())) {
globalStatus = GlobalStatus.RollbackRetrying;
} else if (ExecutionStatus.FA.equals(machineInstance.getStatus()) && machineInstance.getCompensationStatus() == null) {
globalStatus = GlobalStatus.Finished;
} else if (ExecutionStatus.UN.equals(machineInstance.getStatus()) && machineInstance.getCompensationStatus() == null) {
globalStatus = GlobalStatus.CommitRetrying;
} else {
globalStatus = GlobalStatus.UnKnown;
}
sagaTransactionalTemplate.reportTransaction(globalTransaction, globalStatus);
} catch (ExecutionException e) {
LOGGER.error("Report transaction finish to server error: {}, StateMachine: {}, XID: {}, Reason: {}", e.getCode(), machineInstance.getStateMachine().getName(), machineInstance.getId(), e.getMessage(), e);
} catch (TransactionException e) {
LOGGER.error("Report transaction finish to server error: {}, StateMachine: {}, XID: {}, Reason: {}", e.getCode(), machineInstance.getStateMachine().getName(), machineInstance.getId(), e.getMessage(), e);
} finally {
// clear
RootContext.unbind();
RootContext.unbindBranchType();
sagaTransactionalTemplate.triggerAfterCompletion();
sagaTransactionalTemplate.cleanUp();
}
}
}
use of io.seata.tm.api.GlobalTransaction in project seata by seata.
the class InSagaBranchHandlerInterceptor method getXidFromProcessContext.
/**
* Gets xid from saga process context.
*
* @return the xid
*/
protected String getXidFromProcessContext(ProcessContext context) {
String xid = null;
Map<String, Object> contextVariable = (Map<String, Object>) context.getVariable(DomainConstants.VAR_NAME_STATEMACHINE_CONTEXT);
if (contextVariable != null && contextVariable.containsKey(DomainConstants.VAR_NAME_GLOBAL_TX)) {
GlobalTransaction globalTransaction = (GlobalTransaction) contextVariable.get(DomainConstants.VAR_NAME_GLOBAL_TX);
xid = globalTransaction.getXid();
} else {
StateMachineInstance stateMachineInstance = (StateMachineInstance) context.getVariable(DomainConstants.VAR_NAME_STATEMACHINE_INST);
if (stateMachineInstance != null) {
xid = stateMachineInstance.getId();
}
}
return xid;
}
Aggregations