From 62ec8a7349aa6103b49fd098e12d515f08c9de5d Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Wed, 8 Nov 2023 11:54:42 +0800 Subject: [PATCH] resource_control: fix burst patch (#48141) (#48382) close pingcap/tidb#48140 --- .../resourcegroup/resource_group_test.go | 35 ++++++++++++++++++- pkg/parser/model/model.go | 4 +-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/pkg/ddl/tests/resourcegroup/resource_group_test.go b/pkg/ddl/tests/resourcegroup/resource_group_test.go index edee6d95d90ea..a76b34f5532ff 100644 --- a/pkg/ddl/tests/resourcegroup/resource_group_test.go +++ b/pkg/ddl/tests/resourcegroup/resource_group_test.go @@ -137,6 +137,28 @@ func TestResourceGroupBasic(t *testing.T) { } g = testResourceGroupNameFromIS(t, tk.Session(), "y") checkFunc(g) + tk.MustGetErrCode("alter resource group y PRIORITY=hight", mysql.ErrParse) + tk.MustExec("alter resource group y PRIORITY=high") + checkFunc = func(groupInfo *model.ResourceGroupInfo) { + re.Equal(true, groupInfo.ID != 0) + re.Equal("y", groupInfo.Name.L) + re.Equal(groupID.Load(), groupInfo.ID) + re.Equal(uint64(4000), groupInfo.RURate) + re.Equal(int64(4000), groupInfo.BurstLimit) + re.Equal(uint64(16), groupInfo.Priority) + } + g = testResourceGroupNameFromIS(t, tk.Session(), "y") + checkFunc(g) + tk.MustExec("alter resource group y RU_PER_SEC=6000") + checkFunc = func(groupInfo *model.ResourceGroupInfo) { + re.Equal(true, groupInfo.ID != 0) + re.Equal("y", groupInfo.Name.L) + re.Equal(groupID.Load(), groupInfo.ID) + re.Equal(uint64(6000), groupInfo.RURate) + re.Equal(int64(6000), groupInfo.BurstLimit) + } + g = testResourceGroupNameFromIS(t, tk.Session(), "y") + checkFunc(g) tk.MustExec("alter resource group y BURSTABLE RU_PER_SEC=5000 QUERY_LIMIT=(EXEC_ELAPSED='15s' ACTION KILL)") checkFunc = func(groupInfo *model.ResourceGroupInfo) { re.Equal(true, groupInfo.ID != 0) @@ -150,7 +172,18 @@ func TestResourceGroupBasic(t *testing.T) { } g = testResourceGroupNameFromIS(t, tk.Session(), "y") checkFunc(g) - tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 5000 MEDIUM YES EXEC_ELAPSED='15s', ACTION=KILL ")) + tk.MustExec("alter resource group y RU_PER_SEC=6000 BURSTABLE=false") + checkFunc = func(groupInfo *model.ResourceGroupInfo) { + re.Equal(true, groupInfo.ID != 0) + re.Equal("y", groupInfo.Name.L) + re.Equal(groupID.Load(), groupInfo.ID) + re.Equal(uint64(6000), groupInfo.RURate) + re.Equal(int64(6000), groupInfo.BurstLimit) + } + g = testResourceGroupNameFromIS(t, tk.Session(), "y") + checkFunc(g) + tk.MustExec("alter resource group y RU_PER_SEC=5000 BURSTABLE") + tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 5000 HIGH YES EXEC_ELAPSED='15s', ACTION=KILL ")) tk.MustExec("drop resource group y") g = testResourceGroupNameFromIS(t, tk.Session(), "y") re.Nil(g) diff --git a/pkg/parser/model/model.go b/pkg/parser/model/model.go index 48ff5665a51ef..9894387dd6293 100644 --- a/pkg/parser/model/model.go +++ b/pkg/parser/model/model.go @@ -2079,8 +2079,8 @@ func (p *ResourceGroupSettings) String() string { // Adjust adjusts the resource group settings. func (p *ResourceGroupSettings) Adjust() { - // Curretly we only support ru_per_sec sytanx, so BurstLimit(capicity) is always same as ru_per_sec. - if p.BurstLimit == 0 { + // Curretly we only support ru_per_sec sytanx, so BurstLimit(capicity) is always same as ru_per_sec except burstable. + if p.BurstLimit >= 0 { p.BurstLimit = int64(p.RURate) } }