apache / apache/incubator-seata-samples
undo_log不写日志,抛异常不会回滚?
- Dominant language
- Java
- Stars
- 2.4k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
Spring Cloud Eureka + Feign + Mybatis
Spring Boot version 2.1.2.RELEASE
Spring Cloud version Greenwich.RELEASE
Seata version 1.1.0
com.alibaba.cloud
spring-cloud-alibaba-seata
2.1.0.RELEASE
seata-all
io.seata
io.seata
seata-all
1.1.0
business-server服务
```
@Override
@GlobalTransactional
public void purchase(String userId, String commodityCode, Integer count) {
// 减库存
storageServiceClient.deduct(commodityCode, count);
// 创建订单
orderServiceClient.create(userId, commodityCode, count);
}
```
order-server服务
```
@Override
public boolean create(String userId, String commodityCode, Integer count) {
// 计算订单金额
final BigDecimal orderMoney = calculate(commodityCode, count);
// 支付
accountServiceClient.debit(userId, orderMoney);
// 保存订单
OrderDTO orderDTO = new OrderDTO();
orderDTO.setUserId(userId);
orderDTO.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
orderDTO.setCommodityCode(commodityCode);
orderDTO.setCount(count);
orderDTO.setMoney(orderMoney);
return orderMapper.insert(orderDTO);
}
```
account-server服务
```
@Override
public void debit(String userId, BigDecimal orderMoney) {
// 查余额
BigDecimal money = accountMapper.queryMoney(userId);
if (money.compareTo(orderMoney) < 0) {
try {
throw new Exception("余额不足");
} catch (Exception e) {
e.printStackTrace();
}
} else {
// 扣钱
accountMapper.debit(userId, orderMoney);
}
}
```
1. 抛异常不会回滚
余额不足抛异常,还是扣了库存,保存了订单
2. undo_log不写日志,没数据
-----------------------------------
2020-03-27 10:52:28.873 WARN 8516 --- [nio-9094-exec-4] c.a.c.seata.web.SeataHandlerInterceptor : xid in change during RPC from 192.168.160.128:8091:2039003107 to null
3. 有时会出现如下异常
-----------------------------------
io.seata.core.exception.RmTransactionException: Response[ TransactionException[Could not register branch into global session xid = 192.168.160.128:8091:2039003036 status = AsyncCommittin ]
Contributor guide
Research direction
Start by tracing the @GlobalTransactional purchase entry point through the Feign calls and the account-server debit method, where the exception is caught. Inspect the undo_log records and the SeataHandlerInterceptor warning while reproducing the insufficient-balance case; done means the rollback behavior and missing transaction records are explained and verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, databases, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100