当前位置:网站首页>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
边栏推荐
- 20220608 other: evaluation of inverse Polish expression
- Leetcode skimming ---367
- Leetcode skimming ---202
- Ut2016 learning notes
- Adaptive Propagation Graph Convolutional Network
- Leetcode刷题---852
- Leetcode - the k-th element in 703 data flow (design priority queue)
- Leetcode skimming ---832
- Softmax regression (pytorch)
- Leetcode skimming ---75
猜你喜欢

侯捷——STL源码剖析 笔记

High imitation Netease cloud music

Raspberry pie 4B deploys lnmp+tor and builds a website on dark web

Softmax 回归(PyTorch)

What did I read in order to understand the to do list

Weight decay (pytorch)

Install yolov3 (Anaconda)

Preliminary knowledge of Neural Network Introduction (pytorch)

Class-Variant Margin Normalized Softmax Loss for Deep Face Recognition

I really want to be a girl. The first step of programming is to wear women's clothes
随机推荐
Leetcode - 706 design hash mapping (Design)*
Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:
Several problems encountered in installing MySQL under MAC system
A complete answer sheet recognition system
Multilayer perceptron (pytorch)
丢弃法Dropout(Pytorch)
【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
Leetcode刷题---44
Jetson TX2 刷机
Hands on deep learning pytorch version exercise solution - 2.4 calculus
Leetcode刷题---278
2018 Lenovo y7000 black apple external display scheme
安装yolov3(Anaconda)
权重衰退(PyTorch)
Rewrite Boston house price forecast task (using paddlepaddlepaddle)
Ut2013 learning notes
8、 Transaction control language of MySQL
Boston house price forecast (tensorflow2.9 practice)
Policy Gradient Methods of Deep Reinforcement Learning (Part Two)
Judging the connectivity of undirected graphs by the method of similar Union and set search