Skip to content

Commit 20c0687

Browse files
HuSharphawkingrei
authored andcommitted
resource_control: support unlimited keyword when setting the resource group (pingcap#54704)
close pingcap#54413
1 parent e15e085 commit 20c0687

File tree

13 files changed

+4642
-4597
lines changed

13 files changed

+4642
-4597
lines changed

pkg/ddl/executor.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -3699,7 +3699,7 @@ func SetDirectResourceGroupSettings(groupInfo *model.ResourceGroupInfo, opt *ast
36993699
resourceGroupSettings := groupInfo.ResourceGroupSettings
37003700
switch opt.Tp {
37013701
case ast.ResourceRURate:
3702-
resourceGroupSettings.RURate = opt.UintValue
3702+
return SetDirectResourceGroupRUSecondOption(resourceGroupSettings, opt.UintValue, opt.BoolValue)
37033703
case ast.ResourcePriority:
37043704
resourceGroupSettings.Priority = opt.UintValue
37053705
case ast.ResourceUnitCPU:
@@ -3746,6 +3746,17 @@ func SetDirectResourceGroupSettings(groupInfo *model.ResourceGroupInfo, opt *ast
37463746
return nil
37473747
}
37483748

3749+
// SetDirectResourceGroupRUSecondOption tries to set ru second part of the ResourceGroupSettings.
3750+
func SetDirectResourceGroupRUSecondOption(resourceGroupSettings *model.ResourceGroupSettings, intVal uint64, unlimited bool) error {
3751+
if unlimited {
3752+
resourceGroupSettings.RURate = uint64(math.MaxInt32)
3753+
resourceGroupSettings.BurstLimit = -1
3754+
} else {
3755+
resourceGroupSettings.RURate = intVal
3756+
}
3757+
return nil
3758+
}
3759+
37493760
// SetDirectResourceGroupRunawayOption tries to set runaway part of the ResourceGroupSettings.
37503761
func SetDirectResourceGroupRunawayOption(resourceGroupSettings *model.ResourceGroupSettings, opt *ast.ResourceGroupRunawayOption) error {
37513762
if resourceGroupSettings.Runaway == nil {

pkg/ddl/tests/resourcegroup/resource_group_test.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package resourcegrouptest_test
1717
import (
1818
"context"
1919
"fmt"
20+
"math"
2021
"sync/atomic"
2122
"testing"
2223
"time"
@@ -92,11 +93,13 @@ func TestResourceGroupBasic(t *testing.T) {
9293

9394
tk.MustExec("set global tidb_enable_resource_control = off")
9495
tk.MustGetErrCode("alter resource group x RU_PER_SEC=2000 ", mysql.ErrResourceGroupSupportDisabled)
96+
tk.MustGetErrCode("alter resource group x RU_PER_SEC=unlimited ", mysql.ErrResourceGroupSupportDisabled)
9597
tk.MustGetErrCode("drop resource group x ", mysql.ErrResourceGroupSupportDisabled)
9698

9799
tk.MustExec("set global tidb_enable_resource_control = DEFAULT")
98100

99101
tk.MustGetErrCode("create resource group x RU_PER_SEC=1000 ", mysql.ErrResourceGroupExists)
102+
tk.MustGetErrCode("create resource group x RU_PER_SEC=UNLIMITED ", mysql.ErrResourceGroupExists)
100103

101104
tk.MustExec("alter resource group x RU_PER_SEC=2000 BURSTABLE QUERY_LIMIT=(EXEC_ELAPSED='15s' ACTION DRYRUN WATCH SIMILAR DURATION '10m0s')")
102105
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
@@ -107,16 +110,27 @@ func TestResourceGroupBasic(t *testing.T) {
107110
re.Equal(model.WatchSimilar, g.Runaway.WatchType)
108111
re.Equal(int64(time.Minute*10/time.Millisecond), g.Runaway.WatchDurationMs)
109112

110-
tk.MustExec("alter resource group x QUERY_LIMIT=(EXEC_ELAPSED='20s' ACTION DRYRUN WATCH SIMILAR)")
113+
tk.MustExec("alter resource group x QUERY_LIMIT=(EXEC_ELAPSED='20s' ACTION DRYRUN WATCH SIMILAR) BURSTABLE=FALSE")
111114
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
112115
re.Equal(uint64(2000), g.RURate)
113-
re.Equal(int64(-1), g.BurstLimit)
116+
re.Equal(int64(2000), g.BurstLimit)
114117
re.Equal(uint64(time.Second*20/time.Millisecond), g.Runaway.ExecElapsedTimeMs)
115118
re.Equal(model.RunawayActionDryRun, g.Runaway.Action)
116119
re.Equal(model.WatchSimilar, g.Runaway.WatchType)
117120
re.Equal(int64(0), g.Runaway.WatchDurationMs)
118121

119-
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 2000 MEDIUM YES EXEC_ELAPSED='20s', ACTION=DRYRUN, WATCH=SIMILAR DURATION=UNLIMITED <nil>"))
122+
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 2000 MEDIUM NO EXEC_ELAPSED='20s', ACTION=DRYRUN, WATCH=SIMILAR DURATION=UNLIMITED <nil>"))
123+
124+
tk.MustExec("alter resource group x RU_PER_SEC= unlimited QUERY_LIMIT=(EXEC_ELAPSED='15s' ACTION DRYRUN WATCH SIMILAR DURATION '10m0s')")
125+
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
126+
re.Equal(uint64(math.MaxInt32), g.RURate)
127+
re.Equal(int64(-1), g.BurstLimit)
128+
re.Equal(uint64(time.Second*15/time.Millisecond), g.Runaway.ExecElapsedTimeMs)
129+
re.Equal(model.RunawayActionDryRun, g.Runaway.Action)
130+
re.Equal(model.WatchSimilar, g.Runaway.WatchType)
131+
re.Equal(int64(time.Minute*10/time.Millisecond), g.Runaway.WatchDurationMs)
132+
133+
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x UNLIMITED MEDIUM YES EXEC_ELAPSED='15s', ACTION=DRYRUN, WATCH=SIMILAR DURATION='10m0s' <nil>"))
120134

121135
tk.MustExec("drop resource group x")
122136
g = testResourceGroupNameFromIS(t, tk.Session(), "x")

pkg/domain/runaway.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (do *Domain) GetRunawayWatchList() []*resourcegroup.QuarantineRecord {
216216
return do.runawayManager.GetWatchList()
217217
}
218218

219-
// TryToUpdateRunawayWatch is used to to update watch list including
219+
// TryToUpdateRunawayWatch is used to update watch list including
220220
// creation and deletion by manual trigger.
221221
func (do *Domain) TryToUpdateRunawayWatch() error {
222222
return do.updateNewAndDoneWatch()

pkg/executor/infoschema_reader.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3618,7 +3618,8 @@ func (e *memtableRetriever) setDataFromResourceGroups() error {
36183618
burstable := burstdisableStr
36193619
priority := model.PriorityValueToName(uint64(group.Priority))
36203620
fillrate := unlimitedFillRate
3621-
isDefaultInReservedSetting := group.Name == resourcegroup.DefaultResourceGroupName && group.RUSettings.RU.Settings.FillRate == math.MaxInt32
3621+
// RU_PER_SEC = unlimited like the default group settings.
3622+
isDefaultInReservedSetting := group.RUSettings.RU.Settings.FillRate == math.MaxInt32
36223623
if !isDefaultInReservedSetting {
36233624
fillrate = strconv.FormatUint(group.RUSettings.RU.Settings.FillRate, 10)
36243625
}

pkg/executor/internal/querywatch/query_watch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func fromQueryWatchOptionList(ctx context.Context, sctx, newSctx sessionctx.Cont
132132

133133
// validateWatchRecord follows several designs:
134134
// 1. If no resource group is set, the default resource group is used
135-
// 2. If no action is specified, the action of the resource group is used. If no, an error message is displayed.
135+
// 2. If no action is specified, the action of the resource group is used. If no, an error message displayed.
136136
func validateWatchRecord(record *resourcegroup.QuarantineRecord, client *rmclient.ResourceGroupsController) error {
137137
if len(record.ResourceGroupName) == 0 {
138138
record.ResourceGroupName = resourcegroup.DefaultResourceGroupName

pkg/meta/meta.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ func (m *Meta) GetResourceGroup(groupID int64) (*model.ResourceGroupInfo, error)
12881288
return nil, errors.Trace(err)
12891289
}
12901290
if value == nil {
1291-
// the default group is not persistanted to tikv by default.
1291+
// the default group is not persistent to tikv by default.
12921292
if groupID == defaultGroupID {
12931293
return defaultRGroupMeta, nil
12941294
}

pkg/parser/ast/ddl.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,11 @@ func (n *ResourceGroupOption) Restore(ctx *format.RestoreCtx) error {
22022202
case ResourceRURate:
22032203
ctx.WriteKeyWord("RU_PER_SEC ")
22042204
ctx.WritePlain("= ")
2205-
ctx.WritePlainf("%d", n.UintValue)
2205+
if n.BoolValue {
2206+
ctx.WriteKeyWord("UNLIMITED")
2207+
} else {
2208+
ctx.WritePlainf("%d", n.UintValue)
2209+
}
22062210
case ResourcePriority:
22072211
ctx.WriteKeyWord("PRIORITY ")
22082212
ctx.WritePlain("= ")

pkg/parser/keywords.go

+1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ var Keywords = []KeywordsType{
622622
{"VALIDATION", false, "unreserved"},
623623
{"VALUE", false, "unreserved"},
624624
{"VARIABLES", false, "unreserved"},
625+
{"VECTOR", false, "unreserved"},
625626
{"VIEW", false, "unreserved"},
626627
{"VISIBLE", false, "unreserved"},
627628
{"WAIT", false, "unreserved"},

pkg/parser/keywords_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestKeywords(t *testing.T) {
3636
}
3737

3838
func TestKeywordsLength(t *testing.T) {
39-
require.Equal(t, 653, len(parser.Keywords))
39+
require.Equal(t, 654, len(parser.Keywords))
4040

4141
reservedNr := 0
4242
for _, kw := range parser.Keywords {

pkg/parser/model/model.go

-6
Original file line numberDiff line numberDiff line change
@@ -2002,12 +2002,6 @@ func (t RunawayActionType) String() string {
20022002
}
20032003
}
20042004

2005-
// ResourceGroupRefInfo is the struct to refer the resource group.
2006-
type ResourceGroupRefInfo struct {
2007-
ID int64 `json:"id"`
2008-
Name CIStr `json:"name"`
2009-
}
2010-
20112005
// ResourceGroupRunawaySettings is the runaway settings of the resource group
20122006
type ResourceGroupRunawaySettings struct {
20132007
ExecElapsedTimeMs uint64 `json:"exec_elapsed_time_ms"`

0 commit comments

Comments
 (0)