seata-samples icon indicating copy to clipboard operation
seata-samples copied to clipboard

saga 中补偿业务的实现。

Open hanxiaolong-github opened this issue 3 years ago • 0 comments

你好: 我看demo 中saga的例子是扣减库存,大概总结下来是: transaction 1: set amount = amount+1 where id = 1;
transaction 2: set amount = amount +2 where id = 1; 当transaction 1 发生错误,需要补偿的时候:业务端 写个方法是: set amount = amount-1 where id = 1; 当transaction 2 发生错误,需要补偿的时候:业务端 写个方法是: set amount = amount-2 where id = 1; 这是正确的。 如果换成字符串好像就不对了,例如: transaction 1: set name = 'n1' where id = 1;
transaction 2: set name = 'n2' where id = 1; 当transaction 1 发生错误,需要补偿的时候:业务端 写个方法是: set name = null where id = 1; 当 transaction 2 补偿的时候 set name = 'n1' where id = 1。最后name 变成了 n1 了。

hanxiaolong-github avatar Jul 15 '22 03:07 hanxiaolong-github