Skip to content

Commit

Permalink
store: avoid setting ratelimit action in tracker when disabled (#31110)
Browse files Browse the repository at this point in the history
ref #30353
  • Loading branch information
Yisaer authored Mar 29, 2022
1 parent c58e005 commit 09edaee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import (
newTestkit "github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
Expand Down Expand Up @@ -3986,6 +3987,18 @@ func (s *testSessionSuite2) TestSetEnableRateLimitAction(c *C) {
// assert default value
result := tk.MustQuery("select @@tidb_enable_rate_limit_action;")
result.Check(testkit.Rows("1"))
tk.MustExec("use test")
tk.MustExec("create table tmp123(id int)")
tk.MustQuery("select * from tmp123;")
haveRateLimitAction := false
action := tk.Se.GetSessionVars().StmtCtx.MemTracker.GetFallbackForTest()
for ; action != nil; action = action.GetFallback() {
if action.GetPriority() == memory.DefRateLimitPriority {
haveRateLimitAction = true
break
}
}
c.Assert(haveRateLimitAction, IsTrue)

// assert set sys variable
tk.MustExec("set global tidb_enable_rate_limit_action= '0';")
Expand All @@ -3996,6 +4009,16 @@ func (s *testSessionSuite2) TestSetEnableRateLimitAction(c *C) {
tk.Se = se
result = tk.MustQuery("select @@tidb_enable_rate_limit_action;")
result.Check(testkit.Rows("0"))

haveRateLimitAction = false
action = tk.Se.GetSessionVars().StmtCtx.MemTracker.GetFallbackForTest()
for ; action != nil; action = action.GetFallback() {
if action.GetPriority() == memory.DefRateLimitPriority {
haveRateLimitAction = true
break
}
}
c.Assert(haveRateLimitAction, IsFalse)
}

func (s *testSessionSuite3) TestSetVarHint(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion store/copr/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *CopClient) Send(ctx context.Context, req *kv.Request, variables interfa
it.sendRate = util.NewRateLimit(it.concurrency)
}
it.actionOnExceed = newRateLimitAction(uint(it.sendRate.GetCapacity()))
if sessionMemTracker != nil {
if sessionMemTracker != nil && enabledRateLimitAction {
sessionMemTracker.FallbackOldAndSetNewAction(it.actionOnExceed)
}

Expand Down

0 comments on commit 09edaee

Please sign in to comment.