use of io.seata.core.model.GlobalStatus 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.core.model.GlobalStatus in project Mycat2 by MyCATApache.
the class SeataTransactionSession method begin.
@Override
@SneakyThrows
public void begin() {
if (tx == null) {
tx = GlobalTransactionContext.createNew();
}
String xid = RootContext.getXID();
if (xid == null) {
GlobalStatus localStatus = tx.getLocalStatus();
switch(localStatus) {
case Rollbacked:
case Committed:
case Finished:
case UnKnown:
for (Map.Entry<String, DefaultConnection> e : updateConnectionMap.entrySet()) {
e.getValue().close();
}
updateConnectionMap.clear();
tx.begin();
mycatXid = tx.getXid();
break;
case Begin:
case Committing:
case CommitRetrying:
case Rollbacking:
case RollbackRetrying:
case TimeoutRollbacking:
case TimeoutRollbackRetrying:
case AsyncCommitting:
case CommitFailed:
case RollbackFailed:
case TimeoutRollbacked:
case TimeoutRollbackFailed:
default:
}
}
dataContext.setInTransaction(true);
}
use of io.seata.core.model.GlobalStatus in project XHuiCloud by sindaZeng.
the class SessionHelper method endRollbacked.
/**
* End rollbacked.
*
* @param globalSession the global session
* @throws TransactionException the transaction exception
*/
public static void endRollbacked(GlobalSession globalSession) throws TransactionException {
GlobalStatus currentStatus = globalSession.getStatus();
if (isTimeoutGlobalStatus(currentStatus)) {
globalSession.changeStatus(GlobalStatus.TimeoutRollbacked);
} else {
globalSession.changeStatus(GlobalStatus.Rollbacked);
}
globalSession.end();
}
use of io.seata.core.model.GlobalStatus in project XHuiCloud by sindaZeng.
the class SessionHolder method reload.
// region reload
/**
* Reload.
*/
protected static void reload(StoreMode storeMode) {
if (ROOT_SESSION_MANAGER instanceof Reloadable) {
((Reloadable) ROOT_SESSION_MANAGER).reload();
}
Collection<GlobalSession> allSessions = ROOT_SESSION_MANAGER.allSessions();
if (CollectionUtils.isNotEmpty(allSessions)) {
List<GlobalSession> removeGlobalSessions = new ArrayList<>();
Iterator<GlobalSession> iterator = allSessions.iterator();
while (iterator.hasNext()) {
GlobalSession globalSession = iterator.next();
GlobalStatus globalStatus = globalSession.getStatus();
switch(globalStatus) {
case UnKnown:
case Committed:
case CommitFailed:
case Rollbacked:
case RollbackFailed:
case TimeoutRollbacked:
case TimeoutRollbackFailed:
case Finished:
removeGlobalSessions.add(globalSession);
break;
case AsyncCommitting:
if (storeMode == StoreMode.FILE) {
queueToAsyncCommitting(globalSession);
}
break;
default:
{
if (storeMode == StoreMode.FILE) {
lockBranchSessions(globalSession.getSortedBranches());
switch(globalStatus) {
case Committing:
case CommitRetrying:
queueToRetryCommit(globalSession);
break;
case Rollbacking:
case RollbackRetrying:
case TimeoutRollbacking:
case TimeoutRollbackRetrying:
queueToRetryRollback(globalSession);
break;
case Begin:
globalSession.setActive(true);
break;
default:
throw new ShouldNeverHappenException("NOT properly handled " + globalStatus);
}
}
break;
}
}
}
for (GlobalSession globalSession : removeGlobalSessions) {
removeInErrorState(globalSession);
}
}
}
use of io.seata.core.model.GlobalStatus in project XHuiCloud by sindaZeng.
the class GlobalSession method queueToRetryRollback.
public void queueToRetryRollback() throws TransactionException {
this.addSessionLifecycleListener(SessionHolder.getRetryRollbackingSessionManager());
SessionHolder.getRetryRollbackingSessionManager().addGlobalSession(this);
GlobalStatus currentStatus = this.getStatus();
if (SessionHelper.isTimeoutGlobalStatus(currentStatus)) {
this.changeStatus(GlobalStatus.TimeoutRollbackRetrying);
} else {
this.changeStatus(GlobalStatus.RollbackRetrying);
}
}
Aggregations