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

执行 cancel 和 confirm 抛出异常不是很理解 #118

Open
25762985 opened this issue Dec 31, 2019 · 3 comments
Open

执行 cancel 和 confirm 抛出异常不是很理解 #118

25762985 opened this issue Dec 31, 2019 · 3 comments

Comments

@25762985
Copy link

  1. try 成功了, confirm执行时报错,这时我调用的方法抛出异常
  2. try执行失败,调用某个执行try成功的服务的cancel方法,这个cancel方法也抛出异常
    这两种都会抛出异常,怎么区分是 cancel的异常还是confirm的异常啊,现在的问题是抛出异常后我就会任务他执行失败了,如果cancel异常还好最终会通过重试调用cancel方法会恢复数据,假如是confirm抛出异常我认为他执行失败了,但是最终通过重试执行成功了,这样不就不一致了嘛
@liuyangming
Copy link
Owner

首先,byteTCC的实现中,不对外暴露confirm/cancel逻辑抛出的业务异常:如果confirm/cancel失败,业务系统只会收到SystemException/RuntimeException提示出错。

其次,业务系统也不必关注异常处理,byteTCC会自行执行故障恢复,其逻辑:如果confirm/cancel逻辑抛出的异常导致本地事务提交,byteTCC会认为该confirm/cancel执行成功;如果confirm/cancel逻辑抛出的异常导致本地事务回滚,byteTCC后续就会再次重试该confirm/cancel逻辑,确保它执行且仅被执行一次!

换言之,重试操作byteTCC自己会根据当前事务状态进行控制,业务系统可以不必关注。如果对byteTCC的控制不太放心,不妨模拟各种异常场景验证一下。如果发现问题请在这里提出issue。

@25762985
Copy link
Author

{
"timestamp": 1577776289727,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.transaction.TransactionSystemException",
"message": "JTA failure on commit; nested exception is javax.transaction.SystemException",
"path": "/transfer"
}

这是我用postman执行例子中的转账方法版本是0.4.17,在comfirm逻辑中手动抛了一个异常,最后postman中返回结果是这个, 我的疑惑点是在这种情况下,我是认为分布式事务执行成功了还是失败了呢,如果认为是失败了,bytetcc会通过重试机制调用我这个comfirm方法,这时又执行成功了

@liuyangming
Copy link
Owner

没太明白你的意思,byteTCC到底重试了你的confirm逻辑还是没重试?

另外,不是抛了异常就算失败的,得看是什么异常,那些导致事务提交的异常会被byteTCC认为是confirm/cancel成功了。

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