codingapi / codingapi/tx-lcn

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

Offen
#496 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
4.2k
Forks
1.4k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java, spring
Bereich
backend, databases, distributed-systems
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
32/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.