apache / apache/incubator-seata

批量插入导致查询出错

Open
#2,924 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
26k
Forks
8.8k
Avg merge
1d 8h
Merged PRs (30d)
4

Description

环境:
- jdk1.8
- seata 1.2.0
- mybatis-plus 3.3.2
- shardingsphere 4.1.0

在子事务里面就一条批量插入的语句

```
if (goods != null && !goods.isEmpty()) {
List list = BeanUtil.copyList(goods, XXX.class);
this.saveBatch(list);
//goodsLiveList.forEach(this::save);
}
```

真实执行sql如下:
```
INSERT INTO xxx ( xx,xx,xx ) VALUES ( ?,?,? )
```

发现seata是提交事务后,获取后快照,在InsertExecutor拿不到id,debug发现,seata是通过GeneratedKeysResultSet(shardingsphere)拿到返回结果,但是shardingsphere中的AbstractUnsupportedOperationResultSet是不支持beforeFirst执行的,直接抛出 **SQLFeatureNotSupportedException("beforeFirst")** 异常。导致最后拿不到id,再获取快照时执行的语句如下:

```
select * from xxx where id in ( )
```
这样就出现错误了!

Contributor guide

Open the contributing guide

Research direction

Start with Seata's InsertExecutor and the GeneratedKeysResultSet path described in the report, then inspect ShardingSphere's AbstractUnsupportedOperationResultSet behavior around beforeFirst. Reproduce the saveBatch case with the listed Seata, MyBatis-Plus, and ShardingSphere versions. Done means the batch insert completes without the beforeFirst failure and snapshot lookup receives the inserted IDs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.