-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
急!基于soa的事务管理疑问 #50
Comments
@buguniao 根据你的例子,事务应该是按照下面流程:
|
感谢回信,不过还有点疑问: |
service2必须判断是否加过100,加过才减一百,否则不动。
发自网易邮箱大师
在2016年12月10日 11:10,buguniao 写道:
按照您的代码实现来看,请问如何解决下面这个场景的问题:
1、一个事务下有两个参与者service1、service2,service1 转账100元给service2
2、try 阶段service1减去100元,成功,service2失败
3、开始cancel阶段,将service1、service2都执行cancel方法,service1加100,service2减100
问题:
service2失败,但一定需要cancel吗?
比如 service2中的方法是这样写的:
public void transferTo(TransactionContext transactionContext, long accountId, int amount) {
throw new Exception("我故意抛异常"); // 方法立即抛异常
accoutDao.addBalanceAmount(accountId,amount);// service2 加了100元
}
然后在cancel 阶段 ,service1+100、service2-100
但是service2之前根本没有加过100
结果就是service1 金额正确,service2 金额被无缘无故的减了100
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
我想问下,service1的本地事务是什么时候提交的? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
按照您的代码实现来看,请问如何解决下面这个场景的问题:
1、一个事务下有两个参与者service1、service2,service1 转账100元给service2
2、try 阶段,service1 - 100 ,成功。service2 + 100 ,失败。
3、cancel阶段,service1、service2都执行cancel方法,service1 + 100,service2 - 100
4、 结果就是 service1、 service2 回滚到未转账之前的状态,一切看起来很完美!
但是, service2虽然失败了,但一定需要cancel吗?
比如 service2中的方法是这样写的:
然后在cancel 阶段 ,service1+100、service2-100
但是service2之前根本没有加过100
结果就是service1 金额正确,service2 金额被无缘无故的减了100
问题就在于:基于服务而不是基于数据库资源的事务管理,在不能判断抛异常是由于其他业务逻辑造成还是因为数据库操作失败造成的情况下就进行回滚是存在问题的
The text was updated successfully, but these errors were encountered: