use of io.seata.core.exception.TransactionException in project XHuiCloud by sindaZeng.
the class SessionHolder method queueToRetryRollback.
private static void queueToRetryRollback(GlobalSession globalSession) {
try {
globalSession.addSessionLifecycleListener(getRetryRollbackingSessionManager());
getRetryRollbackingSessionManager().addGlobalSession(globalSession);
} catch (TransactionException e) {
throw new ShouldNeverHappenException(e);
}
}
use of io.seata.core.exception.TransactionException in project XHuiCloud by sindaZeng.
the class SessionHolder method queueToAsyncCommitting.
private static void queueToAsyncCommitting(GlobalSession globalSession) {
try {
globalSession.addSessionLifecycleListener(getAsyncCommittingSessionManager());
getAsyncCommittingSessionManager().addGlobalSession(globalSession);
} catch (TransactionException e) {
throw new ShouldNeverHappenException(e);
}
}
use of io.seata.core.exception.TransactionException in project XHuiCloud by sindaZeng.
the class SessionHolder method queueToRetryCommit.
private static void queueToRetryCommit(GlobalSession globalSession) {
try {
globalSession.addSessionLifecycleListener(getRetryCommittingSessionManager());
getRetryCommittingSessionManager().addGlobalSession(globalSession);
} catch (TransactionException e) {
throw new ShouldNeverHappenException(e);
}
}
use of io.seata.core.exception.TransactionException in project XHuiCloud by sindaZeng.
the class SagaCore method doGlobalCommit.
@Override
public boolean doGlobalCommit(GlobalSession globalSession, boolean retrying) throws TransactionException {
try {
BranchStatus branchStatus = branchCommit(globalSession, SessionHelper.newBranch(BranchType.SAGA, globalSession.getXid(), -1, getSagaResourceId(globalSession), globalSession.getStatus().name()));
switch(branchStatus) {
case PhaseTwo_Committed:
removeAllBranches(globalSession);
LOGGER.info("Successfully committed SAGA global[" + globalSession.getXid() + "]");
break;
case PhaseTwo_Rollbacked:
LOGGER.info("Successfully rollbacked SAGA global[" + globalSession.getXid() + "]");
removeAllBranches(globalSession);
SessionHelper.endRollbacked(globalSession);
return false;
case PhaseTwo_RollbackFailed_Retryable:
LOGGER.error("By [{}], failed to rollback SAGA global [{}], will retry later.", branchStatus, globalSession.getXid());
SessionHolder.getRetryCommittingSessionManager().removeGlobalSession(globalSession);
globalSession.queueToRetryRollback();
return false;
case PhaseOne_Failed:
LOGGER.error("By [{}], finish SAGA global [{}]", branchStatus, globalSession.getXid());
removeAllBranches(globalSession);
globalSession.changeStatus(GlobalStatus.Finished);
globalSession.end();
return false;
case PhaseTwo_CommitFailed_Unretryable:
if (globalSession.canBeCommittedAsync()) {
LOGGER.error("By [{}], failed to commit SAGA global [{}]", branchStatus, globalSession.getXid());
break;
} else {
SessionHelper.endCommitFailed(globalSession);
LOGGER.error("Finally, failed to commit SAGA global[{}]", globalSession.getXid());
return false;
}
default:
if (!retrying) {
globalSession.queueToRetryCommit();
return false;
} else {
LOGGER.error("Failed to commit SAGA global[{}], will retry later.", globalSession.getXid());
return false;
}
}
} catch (Exception ex) {
LOGGER.error("Failed to commit global[" + globalSession.getXid() + "]", ex);
if (!retrying) {
globalSession.queueToRetryRollback();
}
throw new TransactionException(ex);
}
return true;
}
use of io.seata.core.exception.TransactionException in project seata by seata.
the class DefaultCoordinatorTest method branchCommit.
@Test
public void branchCommit() throws TransactionException {
BranchStatus result = null;
String xid = null;
GlobalSession globalSession = null;
try {
xid = core.begin(applicationId, txServiceGroup, txName, timeout);
Long branchId = core.branchRegister(BranchType.AT, resourceId, clientId, xid, applicationData, lockKeys_1);
globalSession = SessionHolder.findGlobalSession(xid);
result = core.branchCommit(globalSession, globalSession.getBranch(branchId));
} catch (TransactionException e) {
Assertions.fail(e.getMessage());
}
Assertions.assertEquals(result, BranchStatus.PhaseTwo_Committed);
globalSession = SessionHolder.findGlobalSession(xid);
Assertions.assertNotNull(globalSession);
globalSession.end();
}
Aggregations