Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix some missing set kv variables (#18620) #18667

Merged
merged 4 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,7 @@ func (s *session) InitTxnWithStartTS(startTS uint64) error {
if err != nil {
return err
}
txn.SetVars(s.sessionVars.KVVars)
s.txn.changeInvalidToValid(txn)
err = s.loadCommonGlobalVariablesIfNeeded()
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,8 @@ func (s *testSessionSerialSuite) TestKVVars(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("set @@tidb_backoff_lock_fast = 1")
tk.MustExec("set @@tidb_backoff_weight = 100")
tk.MustExec("create table if not exists kvvars (a int)")
tk.MustExec("create table if not exists kvvars (a int key)")
tk.MustExec("insert into kvvars values (1)")
tk.MustExec("begin")
txn, err := tk.Se.Txn(false)
c.Assert(err, IsNil)
Expand All @@ -2649,6 +2650,13 @@ func (s *testSessionSerialSuite) TestKVVars(c *C) {
c.Assert(err, IsNil)
vars = txn.GetVars()
c.Assert(vars.BackOffWeight, Equals, 50)

tk.MustExec("set @@autocommit = 1")
c.Assert(failpoint.Enable("github.com/pingcap/tidb/store/tikv/probeSetVars", `return(true)`), IsNil)
tk.MustExec("select * from kvvars where a = 1")
c.Assert(failpoint.Disable("github.com/pingcap/tidb/store/tikv/probeSetVars"), IsNil)
c.Assert(tikv.SetSuccess, IsTrue)
tikv.SetSuccess = false
}

func (s *testSessionSuite2) TestCommitRetryCount(c *C) {
Expand Down
8 changes: 8 additions & 0 deletions store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,17 @@ func (a assertionPair) String() string {
return fmt.Sprintf("key: %s, assertion type: %d", a.key, a.assertion)
}

// SetSuccess is used to probe if kv variables are set or not. It is ONLY used in test cases.
var SetSuccess = false

func (txn *tikvTxn) SetVars(vars *kv.Variables) {
txn.vars = vars
txn.snapshot.vars = vars
failpoint.Inject("probeSetVars", func(val failpoint.Value) {
if val.(bool) {
SetSuccess = true
}
})
}

func (txn *tikvTxn) GetVars() *kv.Variables {
Expand Down