Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
helloWorld233333333 opened this issue Jun 11, 2024 · 4 comments
Open

Comments

@helloWorld233333333
Copy link

helloWorld233333333 commented Jun 11, 2024

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

}

​`

@helloWorld233333333 helloWorld233333333 changed the title 手动回滚之后不能返回自定义信息吗? 手动回滚之后还会去触发commitTransaction方法? Jun 12, 2024
@funky-eyes
Copy link
Contributor

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

@funky-eyes
Copy link
Contributor

funky-eyes commented Jun 22, 2024

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

@helloWorld233333333
Copy link
Author

我想了解下,为什么有注解的方式,还依然要用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

@funky-eyes
Copy link
Contributor

我想了解下,为什么有注解的方式,还依然要用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

社区目前的考虑是,api就专注于使用api方式管理事务,而注解方式就代表你的事务将被框架托管,理论上不应该再使用api去介入.所以我们需要一个比较明确的理由,让我们认定这是一个bug或者需求
The current consideration of the community is that the API focuses on using the API to manage transactions, and the annotation method means that your transactions will be hosted by the framework, and theoretically you should no longer use the API to intervene. So we need a clear reason to determine that this is a bug or a requirement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants