pingcap / pingcap/tidb

Duplicate entry in optimistic txn retry

Open
#42,613 2 comments 0 reactions 0 assignees View on GitHub
component/ddl type/question
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

cased by https://github.com/pingcap/tidb/pull/20659

```
func (s *testSchemaSuite) TestDisableTxnAutoRetry2(c *C) {
logutil.SetLevel("debug")
defer logutil.SetLevel("info")
tk1 := testkit.NewTestKitWithInit(c, s.store)
tk2 := testkit.NewTestKitWithInit(c, s.store)
tk1.MustExec("create table t (id int auto_increment primary key, idx int unique key, c int)")
tk1.MustExec("insert into t(idx, c) values (1, 1)")
tk1.MustExec("set @@tidb_disable_txn_auto_retry = 0")

tk1.MustExec("begin optimistic")
tk1.MustExec("insert into t(id, idx, c) values (10, 11, 12)")
tk1.MustExec("insert into t (idx, c) values (13, 14)")
tk1.MustExec("update t set c = 0 where idx = 1")

tk2.MustExec("begin optimistic")
tk2.MustExec("update t set c = 100 where idx = 1")
tk2.MustExec("commit")

tk1.MustExec("commit")
}
```

### 2. What did you expect to see? (Required)

case pass

### 3. What did you see instead (Required)

```
session_test.go:2757:
tk1.MustExec("commit")
/Users/mobike/Downloads/workspace/tidb5.0/tidb3.0.5/util/testkit/testkit.go:217:
tk.c.Assert(err, check.IsNil, check.Commentf("sql:%s, %v, error stack %v", sql, args, errors.ErrorStack(err)))
... value *errors.withMessage = previous statement: update t set c = 0 where idx = 1: [kv:1062]Duplicate entry '10' for key 'PRIMARY'
... sql:commit, [], error stack [kv:1062]Duplicate entry '10' for key 'PRIMARY'
previous statement: update t set c = 0 where idx = 1

```
### 4. What is your TiDB version? (Required)

Release Version: v5.0.0
Edition: Community
Git Commit Hash: bdac0885cd11bdf571aad9353bfc24e13554b91c
Git Branch: HEAD
UTC Build Time: 2023-03-27 12:40:49
GoVersion: go1.14.15
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.