apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
https://seata.apache.org/
Apache License 2.0
25.08k stars 8.73k forks source link

手动回滚之后还会去触发commitTransaction方法? #6607

Open helloWorld233333333 opened 3 weeks ago

helloWorld233333333 commented 3 weeks ago

回滚是正常的,但是最后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());

}

​`

funky-eyes commented 2 weeks ago

请问你使用的什么版本? What version are you using?

funky-eyes commented 2 weeks ago

我想了解下,为什么有注解的方式,还依然要用api加以配合呢? I would like to understand, why do we still use APIs in conjunction with annotations?

helloWorld233333333 commented 1 week ago

我想了解下,为什么有注解的方式,还依然要用api加以配合呢? I would like to understand, why do we still use APIs in conjunction with annotations?

你好,我用的是2.0.0版本 我想的是如果后续的代码还需要执行的话,就使用了手动回滚,但是在手动回滚之后,注解所触发的事务进程并没有被终止,导致最后return的时候还会去提交,触发了Global transaction[%s] not found, may be rollbacked.,所以感觉很奇怪 image