pingcap / pingcap/tidb

unistore: unrepeatable read

Open
#57,170 0 comments 0 reactions 0 assignees View on GitHub
type/bug
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)

```go
func TestMaxPositionRepeatableRead(t *testing.T) {
store := testkit.CreateMockStore(t)

tk1 := testkit.NewTestKit(t, store)
tk2 := testkit.NewTestKit(t, store)
tk1.MustExec("use test")
tk2.MustExec("use test")

// Create and initialize the test table
tk1.MustExec("drop table if exists sample_table")
tk1.MustExec(`CREATE TABLE sample_table (
id INT,
position INT,
value VARCHAR(255),
PRIMARY KEY (id, position)
)`)

tk1.MustExec(`INSERT INTO sample_table (id, position, value) VALUES
(1, 1, 'First value'),
(1, 2, 'Second value'),
(2, 1, 'Another value'),
(2, 2, 'Yet another value'),
(3, 1, 'Different id value')`)

// Start transaction in tk2 first
tk2.MustExec("begin")

// Check initial max position
rows := tk2.MustQuery("select max(position) from sample_table where id = 1").Rows()
require.Equal(t, "2", rows[0][0])

// Insert new row in tk1
tk1.MustExec("begin")
tk1.MustExec("insert into sample_table (id, position, value) values (1, 3, 'test')")
tk1.MustExec("commit")

// Check max position again in tk2, should still be 2 due to repeatable read
rows = tk2.MustQuery("select max(position) from sample_table where id = 1").Rows()
require.Equal(t, "2", rows[0][0], "Transaction isolation (repeatable read) violated: saw result from concurrent transaction")

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

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

The last query returns 2.

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

The last query may return 3.

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

v6.5, v8.4, and possibly every version in between

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.