codingapi / codingapi/tx-lcn

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

オープン
#496 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Java
スター
4.2k
フォーク
1.4k
PR マージ指標
30日以内にマージされた PR はありません

説明

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]
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Start with the TestServiceImpl example and DescriptionDao.deleteById(Integer.valueOf(2)) to trace how the deleted entity is captured and how its undo INSERT parameters are assembled. Reproduce the txc rollback with the provided table and logs, then verify that compensation binds only the three INSERT values and restores the deleted row without the extra null parameter.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java, spring
領域
backend, databases, distributed-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
32/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。