apache / apache/incubator-seata

TIDB接seata,测试分布式事务报错SQLException: io.seata.common.exception.ShouldNeverHappenException

Open
#5,327 7 comments 0 reactions 0 assignees View on GitHub
task: help-wanted type: discussion
Dominant language
Java
Stars
26k
Forks
8.8k
Avg merge
1d 8h
Merged PRs (30d)
4

Description

- [ ] I have searched the [issues](https://github.com/seata/seata/issues) of this repository and believe that this is not a duplicate.

### Ⅰ. Issue Description
TIDB接Seata,数据库表结构主键字段,按照TIDB官方建议设置的是AUTO_RANDOM,没有设置AUTO_INCREMENT,主要是规避数据热点问题(PS:如果设置AUTO_INCREMENT seata能正常运作)
CREATE TABLE `inventory_balance_detail` (
`inventory_balance_detail_id` bigint(20) NOT NULL
/*T![auto_rand] AUTO_RANDOM(5) */,
`tenantsid` bigint(20) NOT NULL DEFAULT '0' COMMENT '租户ID',
`item_no` varchar(40) NOT NULL DEFAULT '' COMMENT '品号',
`item_name` varchar(60) NOT NULL DEFAULT '' COMMENT '品名'
`modified_date` datetime DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`inventory_balance_detail_id`)
/*T![clustered_index] CLUSTERED */,
UNIQUE KEY `inventory_balance_detail_uk` (
`item_no`
)
) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_bin
/*T![auto_rand_base] AUTO_RANDOM_BASE=30001 */
COMMENT = 'XXXX'

### Ⅱ. Describe what happened
测试分布式事务报错如下:
"message": "SQLException: io.seata.common.exception.ShouldNeverHappenException

Just paste your stack trace here!
Caused by: com.XXXXXXX.exceptions.DWDataException: In DWDataSet. The DWDataTableName : inventory_balance_detail -> DWDataRowState : C -> DWDataRowIndex : 0 is error. io.seata.common.exception.ShouldNeverHappenException Query: INSERT INTO inventory_balance_detail(item_no, item_name, item_spec, item_feature_no, item_feature_spec, warehouse_no, warehouse_name, inventory_qty, inv_unit_no, inventory_unit_name, last_stock_out_date, last_stock_in_date, storage_spaces_no, storage_spaces_name, lot_no, lot_description, remark, eoc_company_id, eoc_site_id, create_by, create_date, tenantsid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Parameters: [[001005, , , , , 001, , 0, , , 1900-01-01, 1900-01-01, , , , , , 1, 1, LXQ0406, 2023-02-08 14:22:58.608, 509432491012672]]
at com.XXXXXXX.exceptions.DWDataException.rethrow(DWDataException.java:55)
at com.XXXXXXX.dao.generic.DWDataSetDaoImpl.execute(DWDataSetDaoImpl.java:560)
at com.XXXXXXX.CreateInventoryBalanceDetailInfoService.doInventoryBalanceDetailInfo(CreateInventoryBalanceDetailInfoService.java:107)
at com.XXXXXXX.CreateInventoryBalanceDetailInfoService.createInventoryBalanceDetailInfo(CreateInventoryBalanceDetailInfoService.java:52)
at com.XXXXXXX.CreateInventoryBalanceDetailInfoService$$FastClassBySpringCGLIB$$e1a4789.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at com.XXXXXXX.container.ServicePublicMethodLogInterceptor.invoke(ServicePublicMethodLogInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at io.seata.spring.annotation.GlobalTransactionalInterceptor$2.execute(GlobalTransactionalInterceptor.java:184)
at io.seata.tm.api.TransactionalTemplate.execute(TransactionalTemplate.java:127)
at io.seata.spring.annotation.GlobalTransactionalInterceptor.handleGlobalTransaction(GlobalTransactionalInterceptor.java:181)
at io.seata.spring.annotation.GlobalTransactionalInterceptor.invoke(GlobalTransactionalInterceptor.java:150)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
at com.XXXXXXX.CreateInventoryBalanceDetailInfoService$$EnhancerBySpringCGLIB$$ae6b3e1d.createInventoryBalanceDetailInfo()
at com.XXXXXXX.createInventoryBalanceDetailInfo(InventoryService.java:51)
at com.XXXXXXX.InventoryService$$FastClassBySpringCGLIB$$67118c36.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)

### Ⅲ. Describe what you expected to happen
数据能正常新增到DB

### Ⅳ. How to reproduce it (as minimally and precisely as possible)
### Ⅴ. Anything else we need to know?
### Ⅵ. Environment:

- JDK version :openjdk-1.8.0.212
- Seata version: 1.4.2
- OS :Linux dcinvbackend-deployment-a-bc776c587-v5jfn 3.10.0-862.14.1.5.h520.eulerosv2r7.x86_64
- Others:

Contributor guide

Open the contributing guide

Research direction

Start with the reported inventory_balance_detail schema and the INSERT stack trace, comparing TiDB AUTO_RANDOM with AUTO_INCREMENT under Seata 1.4.2. Reproduce the distributed transaction using the provided environment details and identify why the AUTO_RANDOM primary key causes ShouldNeverHappenException; done means the row is inserted successfully without changing the intended schema.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.