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

### 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]