Lcn模式,Feign被调用方异常,无法回滚整个事务(解决了,使用多数据库解决)
- [ ] I have searched the issues of this repository and believe that this is not a duplicate.
1. Bug Description
在服务的被调用方,报错误: 2020-03-09 15:39:00.224 ERROR 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: business code error
////////////////////////////////////////////////调用方代码如下:
/**
* 添加租房信息
* @param rentedInfo 租房信息
* @return 成功返回true否则返回false
*/
@LcnTransaction
@Transactional
@Override
public Boolean addRented(RentedInfo rentedInfo) {
String authorization = httpServletRequest.getHeader("Authorization");
//这里调用House服务,必须拿到返回值手动返回 才能正常回滚,如果不手动返回则无法回滚
//这就不是分布式事务了吧
Message message = houseFeign.modifyStatus(authorization, rentedInfo.getHid());
if (message.getCode() != 30006){
return false;
}
Integer integer = rentMapper.addRented(rentedInfo);
if (integer != 0) {
return true;
}
return false;
}
//////////////////////////////////////////////////这里是调用方的日志 },Server stats: [[Server:192.168.0.107:53050; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0] ]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@48979a69 2020-03-09 15:39:00.324 DEBUG 5840 --- [io-53022-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: business success 2020-03-09 15:39:00.325 DEBUG 5840 --- [io-53022-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: notify group > [lcn, 1] > groupId: {xid}, unitId: {uid}, state: {}. 2020-03-09 15:39:00.325 DEBUG 5840 --- [io-53022-exec-1] c.c.t.txmsg.netty.bean.SocketManager : get channel, key:/127.0.0.1:8070 2020-03-09 15:39:00.325 DEBUG 5840 --- [io-53022-exec-1] c.c.t.txmsg.netty.bean.SocketManager : await response 2020-03-09 15:39:00.325 DEBUG 5840 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdEncoder : send->{"key":"3474671093194208","msg":{"action":"notifyGroup","data":{"groupId":"3474671033694208","state":1},"groupId":"3474671033694208","state":100},"remoteKey":"/127.0.0.1:8070"} 2020-03-09 15:39:00.329 DEBUG 5840 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdDecoder : cmd->{"key":"3474671093194208","msg":{"action":"notifyGroup","groupId":"3474671033694208","state":200},"remoteKey":"/127.0.0.1:10746"} 2020-03-09 15:39:00.329 DEBUG 5840 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdDecoder : got response message[Netty Handler] 2020-03-09 15:39:00.329 DEBUG 5840 --- [io-53022-exec-1] c.c.txlcn.txmsg.netty.bean.NettyRpcCmd : got response. 3474671093194208 2020-03-09 15:39:00.329 DEBUG 5840 --- [io-53022-exec-1] c.c.t.txmsg.netty.bean.SocketManager : response is: MessageDto(action=notifyGroup, groupId=3474671033694208, data=null, state=200) 2020-03-09 15:39:00.329 DEBUG 5840 --- [io-53022-exec-1] c.c.t.txmsg.netty.impl.NettyRpcClient : cmd request used time: 4 ms 2020-03-09 15:39:00.329 DEBUG 5840 --- [io-53022-exec-1] c.c.txlcn.tc.txmsg.LoopMessenger : request action: notifyGroup. TM[/127.0.0.1:8070] 2020-03-09 15:39:00.329 DEBUG 5840 --- [io-53022-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: clean transaction 2020-03-09 15:39:00.329 DEBUG 5840 --- [io-53022-exec-1] c.c.t.t.c.t.l.r.LcnConnectionProxy : commit transaction type[lcn] proxy connection:com.codingapi.txlcn.tc.core.transaction.lcn.resource.LcnConnectionProxy@18b2a536. 2020-03-09 15:39:00.330 DEBUG 5840 --- [io-53022-exec-1] c.c.t.t.c.t.l.r.LcnConnectionProxy : transaction type[lcn] proxy connection:com.codingapi.txlcn.tc.core.transaction.lcn.resource.LcnConnectionProxy@18b2a536 closed. 2020-03-09 15:39:00.330 DEBUG 5840 --- [io-53022-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: clean transaction over 2020-03-09 15:39:00.330 DEBUG 5840 --- [io-53022-exec-1] c.c.t.t.c.t.TransactionControlTemplate : lcn > close transaction group. 2020-03-09 15:39:00.330 DEBUG 5840 --- [io-53022-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: notify group exception state [1]. 2020-03-09 15:39:00.330 DEBUG 5840 --- [io-53022-exec-1] c.c.t.t.c.context.DefaultGlobalContext : Destroy TxContext[3474671033694208] 2020-03-09 15:39:00.331 DEBUG 5840 --- [pool-3-thread-2] c.c.t.t.c.aspect.AsyncH2DBAspectLogger : event-clear-start->3474671033694208 2020-03-09 15:39:00.333 DEBUG 5840 --- [io-53022-exec-1] c.c.txlcn.tc.core.DTXLocalContext : clean thread local[DTXLocalContext]: DTXLocalContext(transactionType=lcn, groupId=3474671033694208, unitId=91782df7d1226588829c46c1ae8a591f, resource=null, destroy=true, inGroup=false, attachment=null, sysTransactionState=1, userTransactionState=-1, proxy=true, justNow=false, proxyTmp=false) 2020-03-09 15:39:00.333 DEBUG 5840 --- [io-53022-exec-1] c.c.t.tc.aspect.weave.DTXLogicWeaver : <---- TxLcn end ----> 2020-03-09 15:39:00.340 DEBUG 5840 --- [pool-3-thread-2] c.c.t.t.c.aspect.AsyncH2DBAspectLogger : event-clear-over ok:true ->3474671033694208,time:10 2020-03-09 15:39:01.043 INFO 5840 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty : Flipping property: house-server.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647 2020-03-09 15:43:08.935 INFO 5840 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
///////////////////////////////////被调用方的代码如下
/**
* 修改房屋状态
* 修改为y
* 同步缓存
*
* @param hid hid
* @return 返回true/false
*/
@LcnTransaction
@Transactional
@Override
public Message modifyStatus(String hid) {
Integer integer = 0;
//修改房屋状态
integer = houseMapper.modifyStatus(hid);
int i = 1/0;
return integer != 0 ? new Message(true, StatusCode.UPD_SUCCESS,ResponseMessageConstant.UPDATE_SUCCESS,null)
: new Message(false,StatusCode.UPD_FAIL,ResponseMessageConstant.UPDATE_FAILED,null);
}
/////////////////////////////////////////被调用方日志
2020-03-09 15:39:00.184 DEBUG 17620 --- [io-53050-exec-1] c.c.t.tc.aspect.weave.DTXLogicWeaver : <---- TxLcn start ----> 2020-03-09 15:39:00.184 DEBUG 17620 --- [io-53050-exec-1] c.c.t.t.c.context.DefaultGlobalContext : Start TxContext[3474671079090112] 2020-03-09 15:39:00.185 DEBUG 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: create group > [lcn] > groupId: {xid}, unitId: {uid} 2020-03-09 15:39:00.185 DEBUG 17620 --- [io-53050-exec-1] c.c.t.txmsg.netty.bean.SocketManager : get channel, key:/127.0.0.1:8070 2020-03-09 15:39:00.185 DEBUG 17620 --- [io-53050-exec-1] c.c.t.txmsg.netty.bean.SocketManager : await response 2020-03-09 15:39:00.185 DEBUG 17620 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdEncoder : send->{"key":"3474671079190112","msg":{"action":"createGroup","groupId":"3474671079090112","state":100},"remoteKey":"/127.0.0.1:8070"} 2020-03-09 15:39:00.188 DEBUG 17620 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdDecoder : cmd->{"key":"3474671079190112","msg":{"action":"createGroup","groupId":"3474671079090112","state":200},"remoteKey":"/127.0.0.1:10621"} 2020-03-09 15:39:00.188 DEBUG 17620 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdDecoder : got response message[Netty Handler] 2020-03-09 15:39:00.188 DEBUG 17620 --- [io-53050-exec-1] c.c.txlcn.txmsg.netty.bean.NettyRpcCmd : got response. 3474671079190112 2020-03-09 15:39:00.188 DEBUG 17620 --- [io-53050-exec-1] c.c.t.txmsg.netty.bean.SocketManager : response is: MessageDto(action=createGroup, groupId=3474671079090112, data=null, state=200) 2020-03-09 15:39:00.188 DEBUG 17620 --- [io-53050-exec-1] c.c.t.txmsg.netty.impl.NettyRpcClient : cmd request used time: 3 ms 2020-03-09 15:39:00.188 DEBUG 17620 --- [io-53050-exec-1] c.c.txlcn.tc.txmsg.LoopMessenger : request action: createGroup. TM[/127.0.0.1:8070] 2020-03-09 15:39:00.189 DEBUG 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: create group over 2020-03-09 15:39:00.189 DEBUG 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: pre business code, unit type: [lcn] 2020-03-09 15:39:00.192 DEBUG 17620 --- [pool-3-thread-1] c.c.t.t.c.aspect.AsyncH2DBAspectLogger : event-save-start->3474671079090112 2020-03-09 15:39:00.198 DEBUG 17620 --- [io-53050-exec-1] c.c.t.tc.aspect.weave.DTXResourceWeaver : proxy a sql connection: com.codingapi.txlcn.tc.core.transaction.lcn.resource.LcnConnectionProxy@37d89d12. 2020-03-09 15:39:00.202 DEBUG 17620 --- [pool-3-thread-1] c.c.t.t.c.aspect.AsyncH2DBAspectLogger : event-save-over ok:true ->3474671079090112,time:13 2020-03-09 15:39:00.224 ERROR 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: business code error 2020-03-09 15:39:00.224 DEBUG 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: notify group > [lcn, 0] > groupId: {xid}, unitId: {uid}, state: {}. 2020-03-09 15:39:00.224 DEBUG 17620 --- [io-53050-exec-1] c.c.t.txmsg.netty.bean.SocketManager : get channel, key:/127.0.0.1:8070 2020-03-09 15:39:00.225 DEBUG 17620 --- [io-53050-exec-1] c.c.t.txmsg.netty.bean.SocketManager : await response 2020-03-09 15:39:00.225 DEBUG 17620 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdEncoder : send->{"key":"3474671083090112","msg":{"action":"notifyGroup","data":{"groupId":"3474671079090112","state":0},"groupId":"3474671079090112","state":100},"remoteKey":"/127.0.0.1:8070"} 2020-03-09 15:39:00.230 DEBUG 17620 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdDecoder : cmd->{"key":"3474671083090112","msg":{"action":"notifyGroup","groupId":"3474671079090112","state":200},"remoteKey":"/127.0.0.1:10621"} 2020-03-09 15:39:00.230 DEBUG 17620 --- [ntLoopGroup-4-1] c.c.t.txmsg.netty.handler.RpcCmdDecoder : got response message[Netty Handler] 2020-03-09 15:39:00.231 DEBUG 17620 --- [io-53050-exec-1] c.c.txlcn.txmsg.netty.bean.NettyRpcCmd : got response. 3474671083090112 2020-03-09 15:39:00.231 DEBUG 17620 --- [io-53050-exec-1] c.c.t.txmsg.netty.bean.SocketManager : response is: MessageDto(action=notifyGroup, groupId=3474671079090112, data=null, state=200) 2020-03-09 15:39:00.231 DEBUG 17620 --- [io-53050-exec-1] c.c.t.txmsg.netty.impl.NettyRpcClient : cmd request used time: 7 ms 2020-03-09 15:39:00.231 DEBUG 17620 --- [io-53050-exec-1] c.c.txlcn.tc.txmsg.LoopMessenger : request action: notifyGroup. TM[/127.0.0.1:8070] 2020-03-09 15:39:00.231 DEBUG 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: clean transaction 2020-03-09 15:39:00.231 DEBUG 17620 --- [io-53050-exec-1] c.c.t.t.c.t.l.r.LcnConnectionProxy : rollback transaction type[lcn] proxy connection:com.codingapi.txlcn.tc.core.transaction.lcn.resource.LcnConnectionProxy@37d89d12. 2020-03-09 15:39:00.279 DEBUG 17620 --- [io-53050-exec-1] c.c.t.t.c.t.l.r.LcnConnectionProxy : transaction type[lcn] proxy connection:com.codingapi.txlcn.tc.core.transaction.lcn.resource.LcnConnectionProxy@37d89d12 closed. 2020-03-09 15:39:00.279 DEBUG 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: clean transaction over 2020-03-09 15:39:00.279 DEBUG 17620 --- [io-53050-exec-1] c.c.t.t.c.t.TransactionControlTemplate : lcn > close transaction group. 2020-03-09 15:39:00.279 DEBUG 17620 --- [io-53050-exec-1] c.codingapi.txlcn.logger.Slf4jTxLogger : Transaction: notify group exception state [0]. 2020-03-09 15:39:00.279 DEBUG 17620 --- [io-53050-exec-1] c.c.t.t.c.context.DefaultGlobalContext : Destroy TxContext[3474671079090112] 2020-03-09 15:39:00.280 DEBUG 17620 --- [io-53050-exec-1] c.c.txlcn.tc.core.DTXLocalContext : clean thread local[DTXLocalContext]: DTXLocalContext(transactionType=lcn, groupId=3474671079090112, unitId=1ca0c83e8ed9bfccd492d031da9ffad4, resource=null, destroy=true, inGroup=false, attachment=null, sysTransactionState=0, userTransactionState=-1, proxy=true, justNow=false, proxyTmp=false) 2020-03-09 15:39:00.280 DEBUG 17620 --- [pool-3-thread-2] c.c.t.t.c.aspect.AsyncH2DBAspectLogger : event-clear-start->3474671079090112 2020-03-09 15:39:00.280 DEBUG 17620 --- [io-53050-exec-1] c.c.t.tc.aspect.weave.DTXLogicWeaver : <---- TxLcn end ---->
问题:如果不加上返回值判断,无法进行事务回滚
2. Environment:
- JDK version: 1.8
- OS: windows 10
- TX-LCN version: 5.0.1.RELEASE
- Others: SpringCloud G版 springBoot 2.1.12 springCloud Oauth2 授权认证
3. Exception Stacktrace
Paste your Exception Stacktrace here!
4. Tour Idea
您好,你这个多数据源解决? 什么意思
我也想问这个多数据源解决? 啥意思
我也想问这个多数据源解决? 啥意思
好久前了。。好像是分库解决的,不过没有seata好用