当前位置:网站首页>Common scenarios in which Seata distributed transactions fail and do not take effect (transactions do not rollback)
Common scenarios in which Seata distributed transactions fail and do not take effect (transactions do not rollback)
2022-07-03 10:37:00 【Twilight drainage software】
One 、 Microservices are not normally obtained XID
Check the method :
Call methods in every microservice RootContext.getXID() Check XID
for example , service A Service called B And the service C
Then we can respectively serve A、 service B、 service C Add in the transaction method of
=============== service A
@Service
public class ServiceAImpl implements IServiceA
{
private static final Logger log = LoggerFactory.getLogger(ServiceAImpl.class);
@Autowired
private IServiceB serviceB;
@Autowired
private IServiceC serviceC;
@Override
@GlobalTransactional
@Transactional
public Boolean doA() {
log.info("Seata Global transaction id=================>{}",RootContext.getXID());
//......
}
}
=============== service B
@Service
public class ServiceBImpl implements IServiceB
{
private static final Logger log = LoggerFactory.getLogger(ServiceBImpl.class);
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Boolean doB() {
log.info("Seata Global transaction id=================>{}",RootContext.getXID());
//......
}
}
=============== service C
@Service
public class ServiceCImpl implements IServiceC
{
private static final Logger log = LoggerFactory.getLogger(ServiceCImpl.class);
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Boolean doC() {
log.info("Seata Global transaction id=================>{}",RootContext.getXID());
//......
}
}
(1) see XID Is it null
(2) In every service XID atypism
If there is one of the above two , It's basically because XID Cause the transaction to fail
terms of settlement :
(1)XID Normally, it is passed to the downstream service through the parameters on the request header , Can pass seta Bag getModifyRequest Under the method headers.put Break points for analysis
(2) Directly pass parameters to downstream services in the calling method
=============== service A
@Service
public class ServiceAImpl implements IServiceA
{
private static final Logger log = LoggerFactory.getLogger(ServiceAImpl.class);
@Autowired
private IServiceB serviceB;
@Autowired
private IServiceC serviceC;
@Override
@GlobalTransactional
@Transactional
public Boolean doA() {
String XID = RootContext.getXID();
serviceB.doB(XID);
serviceC.doC(XID);
//......
}
}
=============== service B
@Service
public class ServiceBImpl implements IServiceB
{
private static final Logger log = LoggerFactory.getLogger(ServiceBImpl.class);
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Boolean doB(XID) {
RootContext.bind(XID);
//......
}
}
=============== service C
@Service
public class ServiceCImpl implements IServiceC
{
private static final Logger log = LoggerFactory.getLogger(ServiceCImpl.class);
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Boolean doC(XID) {
RootContext.bind(XID);
//......
}
}
Two 、undo_log Dirty data in the table
When Seata There is no normal end , Each service corresponds to undo_log Table and seata Persistent database brach_table、global_table、lock_table、undo_log There may be dirty data in the table that is not deleted correctly , This causes the service to rollback all the time , But it didn't succeed
** terms of settlement :** eliminate undo_log Tables and seata Persistent database brach_table、global_table、lock_table、undo_log Dirty data in the table
3、 ... and 、Fegin The call uses Fallback Degraded or thrown exceptions are handled globally
In this case, it belongs to seata The service cannot find the exception thrown by the downstream service , The transaction will not trigger rollback
terms of settlement :
(1) adopt GlobalTransactionContext.reload(RootContext.getXID()).rollback() Do a manual rollback
=============== service A
@Service
public class ServiceAImpl implements IServiceA
{
private static final Logger log = LoggerFactory.getLogger(ServiceAImpl.class);
@Autowired
private IServiceB serviceB;
@Autowired
private IServiceC serviceC;
@Override
@GlobalTransactional
@Transactional
public Boolean doA() {
Integer bStatus = serviceB.doB();
if(bStatus == 0){// stay Mybatis in , The return value is 0 Prove that the insertion failed
// Manual rollback
GlobalTransactionContext.reload(RootContext.getXID()).rollback();
return false;
}
Integer cStatus = serviceC.doC();
if(cStatus == 0){// stay Mybatis in , The return value is 0 Prove that the insertion failed
// Manual rollback
GlobalTransactionContext.reload(RootContext.getXID()).rollback();
return false;
}
//......
}
}
=============== service B
@Service
public class ServiceBImpl implements IServiceB
{
private static final Logger log = LoggerFactory.getLogger(ServiceBImpl.class);
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Boolean doB() {
//......
Integer insertStatus = serviceBDAO.insert();
return insertStatus;
}
}
=============== service C
@Service
public class ServiceCImpl implements IServiceC
{
private static final Logger log = LoggerFactory.getLogger(ServiceCImpl.class);
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Boolean doC() {
//......
Integer insertStatus = serviceCDAO.insert();
return insertStatus;
}
}
(2) Through cut class
See official documents for details
边栏推荐
- Leetcode skimming ---832
- [LZY learning notes dive into deep learning] 3.1-3.3 principle and implementation of linear regression
- ECMAScript--》 ES6语法规范 ## Day1
- Notes - regular expressions
- Drop out (pytoch)
- [graduation season] the picture is rich, and frugality is easy; Never forget chaos and danger in peace.
- 八、MySQL之事务控制语言
- Leetcode刷题---189
- 重写波士顿房价预测任务(使用飞桨paddlepaddle)
- Ind wks first week
猜你喜欢
一步教你溯源【钓鱼邮件】的IP地址
Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:
Step 1: teach you to trace the IP address of [phishing email]
神经网络入门之模型选择(PyTorch)
mysql5.7安装和配置教程(图文超详细版)
Handwritten digit recognition: CNN alexnet
GAOFAN Weibo app
I really want to be a girl. The first step of programming is to wear women's clothes
Advantageous distinctive domain adaptation reading notes (detailed)
Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch
随机推荐
Powshell's set location: unable to find a solution to the problem of accepting actual parameters
Ut2014 learning notes
Leetcode刷题---35
Rewrite Boston house price forecast task (using paddlepaddlepaddle)
A complete mall system
【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
Leetcode skimming ---374
Leetcode - 706 design hash mapping (Design)*
Neural Network Fundamentals (1)
侯捷——STL源码剖析 笔记
Class-Variant Margin Normalized Softmax Loss for Deep Face Recognition
Seata分布式事务失效,不生效(事务不回滚)的常见场景
Numpy Foundation
Standard library header file
Ut2014 supplementary learning notes
Knowledge map reasoning -- hybrid neural network and distributed representation reasoning
High imitation wechat
Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:
Jetson TX2 刷机
Leetcode - 1172 plate stack (Design - list + small top pile + stack))