apache / apache/incubator-seata
手动回滚之后还会去触发commitTransaction方法?
- Dominant language
- Java
- Stars
- 26k
- Forks
- 8.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 4
Description
回滚是正常的,但是最后return返回信息的时候触发了TransactionalTemplate的commitTransaction方法,由于手动回滚了,所以是Finished状态。但他的进程并不会终止?
`
@Override
@GlobalTransactional(name = "global-create-order", rollbackFor = Exception.class)
public ResultData createOrder(Order order) {
Integer result = orderMapper.insert(order);
if (result > 0) {
ResultData stoResultData = storageApi.decrease(order.getProductId(), order.getCount());
ResultData accResultData = accountFeign.decrease(order.getUserId(), order.getMoney());
// 全局事务未如期完成,手动回滚,并返回自定义错误信息
if (!Objects.equals(accResultData.getCode(), "200") || !Objects.equals(
stoResultData.getCode(), "200")) {
log.error("stoResultData:{}",stoResultData.getMessage());
log.error("accResultData:{}",accResultData.getMessage());
try {
// 在这里手动回滚
GlobalTransactionContext.reload(RootContext.getXID()).rollback();
} catch (TransactionException e) {
throw new RuntimeException(e);
}
} else {
order.setStatus(1);
orderMapper.updateById(order);
return ResultData.success(order);
}
}
// 返回自定义信息
return ResultData.fail(ReturnCodeEnum.RC999.getCode(), ReturnCodeEnum.RC999.getMessage());
}
`
Contributor guide
Research direction
Start by reproducing the reported flow from the @GlobalTransactional entry point, tracing GlobalTransactionContext.reload(...).rollback() and the TransactionalTemplate commitTransaction call. Confirm why the process remains active after manual rollback; done means the transaction lifecycle is explained or corrected and the behavior is covered by a regression test if one is appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100