codingapi / codingapi/tx-lcn

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

Aperta
#496 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
4.2k
Fork
1.4k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java, spring
Ambito
backend, databases, distributed-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
32/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.