Skip to content

Commit

Permalink
txn: fix invalid transaction error when doing stale read in RC isol…
Browse files Browse the repository at this point in the history
…ation level (#33653) (#33662)

close #30872
  • Loading branch information
ti-srebot authored Aug 2, 2022
1 parent 0eeb0bb commit db22b01
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func newExecutorBuilder(ctx sessionctx.Context, is infoschema.InfoSchema, ti *Te
ctx: ctx,
is: is,
Ti: ti,
snapshotTSCached: isStaleness,
snapshotTS: snapshotTS,
isStaleness: isStaleness,
readReplicaScope: replicaReadScope,
Expand Down
28 changes: 28 additions & 0 deletions executor/stale_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,3 +1245,31 @@ func (s *testStaleTxnSerialSuite) TestStaleReadNoExtraTSORequest(c *C) {
tk.MustQuery("select * from t")
failpoint.Disable("github.com/pingcap/tidb/session/assertTSONotRequest")
}

func (s *testStaleTxnSerialSuite) TestIssue30872(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists test.t1")
}()

// For mocktikv, safe point is not initialized, we manually insert it for snapshot to use.
safePointName := "tikv_gc_safe_point"
safePointValue := "20160102-15:04:05 -0700"
safePointComment := "All versions after safe point can be accessed. (DO NOT EDIT)"
updateSafePoint := fmt.Sprintf(`INSERT INTO mysql.tidb VALUES ('%[1]s', '%[2]s', '%[3]s')
ON DUPLICATE KEY
UPDATE variable_value = '%[2]s', comment = '%[3]s'`, safePointName, safePointValue, safePointComment)
tk.MustExec(updateSafePoint)
tk.MustExec("use test")
tk.MustExec("drop table if exists test.t1")
tk.MustExec("set tidb_txn_mode='pessimistic'")
tk.MustExec("set tx_isolation = 'READ-COMMITTED'")
tk.MustExec("create table t1 (id int primary key, v int)")
tk.MustExec("insert into t1 values(1, 10)")
time.Sleep(time.Millisecond * 100)
tk.MustExec("set @a=now(6)")
time.Sleep(time.Millisecond * 100)
tk.MustExec("update t1 set v=100 where id=1")
tk.MustExec("set autocommit=0")
tk.MustQuery("select * from t1 as of timestamp @a").Check(testkit.Rows("1 10"))
}

0 comments on commit db22b01

Please sign in to comment.