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

store/tikv: remove Variables.Hook #24758

Merged
merged 6 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 11 additions & 12 deletions session/session_fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ package session_test

import (
"context"
"sync/atomic"
"strings"

. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/util/testkit"
)

Expand Down Expand Up @@ -79,20 +79,19 @@ func (s *testSessionSerialSuite) TestGetTSFailDirtyStateInretry(c *C) {

func (s *testSessionSerialSuite) TestKillFlagInBackoff(c *C) {
// This test checks the `killed` flag is passed down to the backoffer through
// session.KVVars. It works by setting the `killed = 3` first, then using
// failpoint to run backoff() and check the vars.Killed using the Hook() function.
// session.KVVars.
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("create table kill_backoff (id int)")
var killValue uint32
tk.Se.GetSessionVars().KVVars.Hook = func(name string, vars *tikv.Variables) {
killValue = atomic.LoadUint32(vars.Killed)
}
c.Assert(failpoint.Enable("github.com/pingcap/tidb/store/tikv/tikvStoreSendReqResult", `return("callBackofferHook")`), IsNil)
// Inject 1 time timeout. If `Killed` is not successfully passed, it will retry and complete query.
c.Assert(failpoint.Enable("github.com/pingcap/tidb/store/tikv/tikvStoreSendReqResult", `return("timeout")->return("")`), IsNil)
defer failpoint.Disable("github.com/pingcap/tidb/store/tikv/tikvStoreSendReqResult")
// Set kill flag and check its passed to backoffer.
tk.Se.GetSessionVars().Killed = 3
tk.MustQuery("select * from kill_backoff")
c.Assert(killValue, Equals, uint32(3))
tk.Se.GetSessionVars().Killed = 1
rs, err := tk.Exec("select * from kill_backoff")
c.Assert(err, IsNil)
_, err = session.ResultSetToStringSlice(context.TODO(), tk.Se, rs)
// `interrupted` is returned when `Killed` is set.
c.Assert(strings.Contains(err.Error(), "Query execution was interrupted"), IsTrue)
}

func (s *testSessionSerialSuite) TestClusterTableSendError(c *C) {
Expand Down
3 changes: 0 additions & 3 deletions store/tikv/kv/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ type Variables struct {
// BackOffWeight specifies the weight of the max back off time duration.
BackOffWeight int

// Hook is used for test to verify the variable take effect.
Hook func(name string, vars *Variables)

// Pointer to SessionVars.Killed
// Killed is a flag to indicate that this query is killed.
Killed *uint32
Expand Down
2 changes: 0 additions & 2 deletions store/tikv/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ func (s *RegionRequestSender) SendReqCtx(
Resp: &kvrpcpb.GCResponse{RegionError: &errorpb.Error{ServerIsBusy: &errorpb.ServerIsBusy{}}},
}, nil, nil)
}
case "callBackofferHook":
bo.SetVarsHook("callBackofferHook", bo.GetVars())
case "requestTiDBStoreError":
if et == tikvrpc.TiDB {
failpoint.Return(nil, nil, tikverr.ErrTiKVServerTimeout)
Expand Down
10 changes: 0 additions & 10 deletions store/tikv/retry/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ const (
)

func (t BackoffType) createFn(vars *kv.Variables) func(context.Context, int) int {
if vars.Hook != nil {
vars.Hook(t.String(), vars)
}
switch t {
case boTiKVRPC, BoTiFlashRPC:
return NewBackoffFn(100, 2000, EqualJitter)
Expand Down Expand Up @@ -431,10 +428,3 @@ func (b *Backoffer) GetBackoffSleepMS() map[BackoffType]int {
func (b *Backoffer) ErrorsNum() int {
return len(b.errors)
}

// SetVarsHook sets the vars.Hook is used for test to verify the variable take effect.
func (b *Backoffer) SetVarsHook(name string, vars *kv.Variables) {
if b.vars != nil && b.vars.Hook != nil {
b.vars.Hook(name, vars)
}
}