Skip to content

Commit

Permalink
cherry pick pingcap#31110 to release-5.4
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
Yisaer authored and ti-srebot committed Mar 29, 2022
1 parent 8effbbc commit 2e9e895
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ import (
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
<<<<<<< HEAD
"github.com/pingcap/tidb/util/collate"
=======
"github.com/pingcap/tidb/util/memory"
>>>>>>> 09edaee06... store: avoid setting ratelimit action in tracker when disabled (#31110)
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
Expand Down Expand Up @@ -3808,6 +3812,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 @@ -3818,6 +3834,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 @@ -130,7 +130,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 2e9e895

Please sign in to comment.