Skip to content

Commit

Permalink
cherry pick pingcap#31110 to release-5.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
Yisaer authored and ti-srebot committed Mar 29, 2022
1 parent ec7d6b3 commit d6e10c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ import (
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
<<<<<<< HEAD
"github.com/pingcap/tidb/util/collate"
=======
"github.com/pingcap/tidb/util"
"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 @@ -3599,6 +3604,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 @@ -3609,6 +3626,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 @@ -117,7 +117,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 d6e10c1

Please sign in to comment.