开发者社区 > 云原生 > 中间件 > 正文

seata中使用mybatisplus批量插入没有执行成功

    entrustBidMapper.deleteById("11111111");
    EntrustBid entrustBid = new EntrustBid();
    entrustBid.setId("11111111");
    entrustBid.setEntrustId("11111111");
    entrustBidMapper.insert(entrustBid);


    entrustBidMapper.deleteById("22222222");
    EntrustBid entrustBid2 = new EntrustBid();
    entrustBid2.setId("22222222");
    entrustBid2.setEntrustId("22222222");
    List<EntrustBid> entrustList = new ArrayList<>();
    entrustList.add(entrustBid2);
    saveBatch(entrustList);

在全局事务中先删除一条数据,然后插入一条数据,两条数据的id保持一致,此时如果使用mybatisplus单条插入则没有问题,使用mybatisplus批量插入没有执行成功。
单条插入的时候由于id一致,第一次分支注册会失败,重试后改变了skipCheckLock字段就能注册成功,如下

2024-07-02 13:06:49.612 DEBUG 12996 --- [nio-8210-exec-2] i.s.c.r.n.AbstractNettyRemotingClient    : offer message: BranchRegisterRequest{xid='172.16.7.244:8091:1612821884433429018', branchType=AT, resourceId='jdbc:mysql://172.16.1.212:8807/gov_finance', lockKey='entrust_bid:11111111', applicationData='{"skipCheckLock":true}'}
2024-07-02 13:06:49.612 DEBUG 12996 --- [Send_RMROLE_1_1] i.s.c.rpc.netty.AbstractNettyRemoting    : write message:SeataMergeMessage BranchRegisterRequest{xid='172.16.7.244:8091:1612821884433429018', branchType=AT, resourceId='jdbc:mysql://172.16.1.212:8807/gov_finance', lockKey='entrust_bid:11111111', applicationData='{"skipCheckLock":true}'}
, channel:[id: 0x1e94ac12, L:/172.16.6.39:61772 - R:/172.16.7.244:8091],active?true,writable?true,isopen?true
2024-07-02 13:06:49.623 DEBUG 12996 --- [ctor_RMROLE_1_1] i.s.c.rpc.netty.AbstractNettyRemoting    : io.seata.core.rpc.netty.RmNettyRemotingClient@30730ee7 msgId:8, body:MergeResultMessage BranchRegisterResponse{branchId=0, resultCode=Failed, msg='TransactionException[Global lock acquire failed xid = 172.16.7.244:8091:1612821884433429018 branchId = 1612821884433429023]'}

2024-07-02 13:06:49.863 DEBUG 12996 --- [nio-8210-exec-2] i.s.c.r.n.AbstractNettyRemotingClient    : offer message: BranchRegisterRequest{xid='172.16.7.244:8091:1612821884433429018', branchType=AT, resourceId='jdbc:mysql://172.16.1.212:8807/gov_finance', lockKey='entrust_bid:11111111', applicationData='{"skipCheckLock":false}'}
2024-07-02 13:06:49.864 DEBUG 12996 --- [Send_RMROLE_1_1] i.s.c.rpc.netty.AbstractNettyRemoting    : write message:SeataMergeMessage BranchRegisterRequest{xid='172.16.7.244:8091:1612821884433429018', branchType=AT, resourceId='jdbc:mysql://172.16.1.212:8807/gov_finance', lockKey='entrust_bid:11111111', applicationData='{"skipCheckLock":false}'}

批量插入时只有第一次注册失败日志,并且插入操作没有执行成功,也没有任何错误信息

2024-07-02 15:29:39.966 DEBUG 22588 --- [nio-8210-exec-2] c.g.entrust.dao.EntrustBidMapper.insert  : ==>  Preparing: INSERT INTO entrust_bid ( id, entrust_id ) VALUES ( ?, ? )
2024-07-02 15:29:39.968 DEBUG 22588 --- [nio-8210-exec-2] c.g.entrust.dao.EntrustBidMapper.insert  : ==> Parameters: 22222222(String), 22222222(String)
2024-07-02 15:29:39.980 DEBUG 22588 --- [nio-8210-exec-2] i.s.c.r.n.AbstractNettyRemotingClient    : offer message: xid=172.16.7.244:8091:1612821884433430391,branchType=AT,resourceId=jdbc:mysql://172.16.1.212:8807/gov_finance,lockKey=entrust_bid:22222222
2024-07-02 15:29:39.981 DEBUG 22588 --- [Send_RMROLE_1_1] i.s.c.rpc.netty.AbstractNettyRemoting    : write message:SeataMergeMessage xid=172.16.7.244:8091:1612821884433430391,branchType=AT,resourceId=jdbc:mysql://172.16.1.212:8807/gov_finance,lockKey=entrust_bid:22222222
, channel:[id: 0x1fa49591, L:/172.16.6.39:51115 - R:/172.16.7.244:8091],active?true,writable?true,isopen?true
2024-07-02 15:29:39.987 DEBUG 22588 --- [ctor_RMROLE_1_1] i.s.c.rpc.netty.AbstractNettyRemoting    : io.seata.core.rpc.netty.RmNettyRemotingClient@67e03559 msgId:13, body:MergeResultMessage BranchRegisterResponse: branchId=0,result code =Failed,getMsg =TransactionException[Global lock acquire failed xid = 172.16.7.244:8091:1612821884433430391 branchId = 1612821884433430402]

2024-07-02 15:29:40.064 DEBUG 22588 --- [ctor_TMROLE_1_1] i.s.c.rpc.netty.AbstractNettyRemoting    : io.seata.core.rpc.netty.TmNettyRemotingClient@d420520 msgId:5, body:globalStatus=Committed,ResultCode=Success,Msg=null

展开
收起
游客gamvuhmmtceso 2024-07-02 15:42:58 13 0
0 条回答
写回答
取消 提交回答

为企业提供高效、稳定、易扩展的中间件产品。

相关电子书

更多
《Seata 1.3 新特性以及如何参与社区》 立即下载
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
低代码开发师(初级)实战教程 立即下载