fengzhongye opened a new issue, #29734:
URL: https://github.com/apache/shardingsphere/issues/29734

   ## Bug Report
   ### Which version of ShardingSphere did you use?
   
   ```
   <dependency>
       <groupId>org.apache.shardingsphere</groupId>
       <artifactId>shardingsphere-jdbc-core</artifactId>
   </dependency>
   
   <dependency>
       <groupId>org.apache.shardingsphere</groupId>
       <artifactId>shardingsphere-transaction-xa-core</artifactId>
   </dependency>
   ```
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   ### Expected behavior
   Updating data based on primary key id will not deadlock
   ### Actual behavior
   Updating data based on primary key id will deadlock
   
![image.png](https://cdn.nlark.com/yuque/0/2024/png/115452/1705365486196-dd26bb2d-c473-4a15-a2cf-84d21c440983.png#averageHue=%23eee7e6&clientId=ub172aebd-5033-4&from=paste&height=379&id=u7a5ca617&originHeight=758&originWidth=3022&originalType=binary&ratio=2&rotation=0&showTitle=false&size=204410&status=done&style=none&taskId=u255a8396-fe34-46f2-bda0-1fa054c7899&title=&width=1511)
   ### Reason analyze (If you can)
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   This is my class.
   ```
   @Override
   @Transactional(isolation = Isolation.READ_COMMITTED)
   public UniSegmentId getNextSegmentId(String bizType) {
           for (int i = 0; i < TinyIdConstants.RETRY; i++) {
               UniIdInfo tinyIdInfo = tinyIdInfoService.queryByBizType(bizType);
               if (tinyIdInfo == null) {
                   throw new TinyIdSysException("找不到业务类型: " + bizType);
               }
               Long newMaxId = tinyIdInfo.getMaxId() + tinyIdInfo.getStep();
               Long oldMaxId = tinyIdInfo.getMaxId();
   
               int row = tinyIdInfoService.updateMaxId(tinyIdInfo.getId(), 
newMaxId, oldMaxId, tinyIdInfo.getVersion(), tinyIdInfo.getBizType());
               if (row == 1) {
                   tinyIdInfo.setMaxId(newMaxId);
                   return convert(bizType, tinyIdInfo);
               } else {
                   log.info("版本号冲突:{}", tinyIdInfo);
               }
           }
       throw new TinyIdSysException("获取下一段冲突");
   }
   
   @Slf4j
   @RestController
   @Tag(name = "订单控制器")
   @RequestMapping("/order")
   @RequiredArgsConstructor
   public class OrderController {
   
       private ExecutorService executorService = 
Executors.newVirtualThreadPerTaskExecutor();
   
       @Resource
       private IdGeneratorFactory idGeneratorFactoryServer;
   
       @GetMapping
       public void get(){
           for(int i = 0; i< 10000; i++){
               executorService.submit(() -> {
                   UniIdGenerator orderItemIdGenerator = 
idGeneratorFactoryServer.getIdGenerator(TinyIdServiceNameConstant.NORMAL_ORDER_ITEM);
                   UniIdGenerator orderIdGenerator = 
idGeneratorFactoryServer.getIdGenerator(TinyIdServiceNameConstant.NORMAL_ORDER);
                   log.info("子订单id: {}", orderItemIdGenerator.nextId());
                   log.info("订单id: {}", orderIdGenerator.nextId());
               });
           }
       }
   
   }
   ```
   The same code, I have no problem using mybatis alone, but introducing 
shardingsphere will lead to deadlock
   ### Example codes for reproduce this issue (such as a github link).
   
[mybatis.zip](https://github.com/apache/shardingsphere/files/13944235/mybatis.zip)
   
[mybatis+shardingjdbc.zip](https://github.com/apache/shardingsphere/files/13944254/mybatis%2Bshardingjdbc.zip)
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to