codingapi / codingapi/tx-lcn

txc模式下根据ID来Delete某条数据时,模拟事务异常后补偿失败

Open
#496 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
4.2k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

demo主要以txlcn-demo构建,版本是5.0.2。大致流程为serviceA调用serviceB删除某条数据的方法,该方法是通过JpaRepository的deleteById实现的。serviceA模拟异常发生后,serviceB开始尝试数据补偿,逆向插入删除的那条数据,但是我根据日志和断点发现,补偿的sql语句是正常的,但是参数数组却多了一个参数,其参数值为null,最终无法执行SQL导致补偿失败。
---
数据库表
```
CREATE TABLE `tb_description` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 19 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
```
数据记录
id|user_id|description
--|:--:|--:
2|123456|will be delete

service B的代码
```
@Service
@Transactional//本地事务
public class TestServiceImpl implements TestService {

@Autowired
DescriptionDao descriptionDao;

@Override
@TxcTransaction//分布式事务
public TbDescription txlcn(Integer userId) {
descriptionDao.deleteById(Integer.valueOf(2));

TbDescription updateDesc = new TbDescription();
updateDesc.setId(1);
updateDesc.setDescription("new");
updateDesc.setUserId(123456);
return updateDesc;
}

}

@Repository
public interface DescriptionDao extends JpaRepository {
}
```
控制台部分日志
```
statement > SELECT tbdescript0_.id AS id1_0_0_, tbdescript0_.description AS descript2_0_0_, tbdescript0_.user_id AS user_id3_0_0_ FROM tb_description tbdescript0_ WHERE tbdescript0_.id = 2
statement > DELETE FROM tb_description WHERE id = 2
txc > Apply undo log. sql: INSERT INTO tb_description(tb_description.user_id, tb_description.description, tb_description.id) values(?, ?, ?), params: [123456, will be delete, 2, null]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.