Skip to content

Commit 1de1a07

Browse files
nolouchghazalfamilyusa
authored andcommitted
resource_group: supports burstable for resource group (pingcap#40925)
close pingcap#40380
1 parent 012251b commit 1de1a07

File tree

9 files changed

+9989
-9941
lines changed

9 files changed

+9989
-9941
lines changed

ddl/ddl_api.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ func SetDirectPlacementOpt(placementSettings *model.PlacementSettings, placement
30343034
}
30353035

30363036
// SetDirectResourceGroupUnit tries to set the ResourceGroupSettings.
3037-
func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettings, typ ast.ResourceUnitType, stringVal string, uintVal uint64) error {
3037+
func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettings, typ ast.ResourceUnitType, stringVal string, uintVal uint64, boolValue bool) error {
30383038
switch typ {
30393039
case ast.ResourceRURate:
30403040
resourceGroupSettings.RURate = uintVal
@@ -3044,6 +3044,16 @@ func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettin
30443044
resourceGroupSettings.IOReadBandwidth = stringVal
30453045
case ast.ResourceUnitIOWriteBandwidth:
30463046
resourceGroupSettings.IOWriteBandwidth = stringVal
3047+
case ast.ResourceBurstableOpiton:
3048+
// Some about BurstLimit(b):
3049+
// - If b == 0, that means the limiter is unlimited capacity. default use in resource controller (burst with a rate within a unlimited capacity).
3050+
// - If b < 0, that means the limiter is unlimited capacity and fillrate(r) is ignored, can be seen as r == Inf (burst with a inf rate within a unlimited capacity).
3051+
// - If b > 0, that means the limiter is limited capacity. (current not used).
3052+
limit := int64(0)
3053+
if boolValue {
3054+
limit = -1
3055+
}
3056+
resourceGroupSettings.BurstLimit = limit
30473057
default:
30483058
return errors.Trace(errors.New("unknown resource unit type"))
30493059
}
@@ -7610,7 +7620,7 @@ func (d *ddl) CreateResourceGroup(ctx sessionctx.Context, stmt *ast.CreateResour
76107620
groupName := stmt.ResourceGroupName
76117621
groupInfo.Name = groupName
76127622
for _, opt := range stmt.ResourceGroupOptionList {
7613-
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue)
7623+
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue, opt.BoolValue)
76147624
if err != nil {
76157625
return err
76167626
}
@@ -7697,7 +7707,7 @@ func (d *ddl) DropResourceGroup(ctx sessionctx.Context, stmt *ast.DropResourceGr
76977707
func buildResourceGroup(oldGroup *model.ResourceGroupInfo, options []*ast.ResourceGroupOption) (*model.ResourceGroupInfo, error) {
76987708
groupInfo := &model.ResourceGroupInfo{Name: oldGroup.Name, ID: oldGroup.ID, ResourceGroupSettings: &model.ResourceGroupSettings{}}
76997709
for _, opt := range options {
7700-
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue)
7710+
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue, opt.BoolValue)
77017711
if err != nil {
77027712
return nil, err
77037713
}

ddl/resource_group_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ func TestResourceGroupBasic(t *testing.T) {
8484

8585
tk.MustGetErrCode("create resource group x RU_PER_SEC=1000 ", mysql.ErrResourceGroupExists)
8686

87-
tk.MustExec("alter resource group x RU_PER_SEC=2000")
87+
tk.MustExec("alter resource group x RU_PER_SEC=2000 BURSTABLE")
8888
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
8989
re.Equal(uint64(2000), g.RURate)
90+
re.Equal(int64(-1), g.BurstLimit)
9091

9192
tk.MustExec("alter resource group if exists not_exists RU_PER_SEC=2000")
9293
// Check warning message

ddl/resourcegroup/group.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
4141
group.RUSettings = &rmpb.GroupRequestUnitSettings{
4242
RU: &rmpb.TokenBucket{
4343
Settings: &rmpb.TokenLimitSettings{
44-
FillRate: options.RURate,
44+
FillRate: options.RURate,
45+
BurstLimit: options.BurstLimit,
4546
},
4647
},
4748
}
@@ -77,17 +78,20 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
7778
group.RawResourceSettings = &rmpb.GroupRawResourceSettings{
7879
Cpu: &rmpb.TokenBucket{
7980
Settings: &rmpb.TokenLimitSettings{
80-
FillRate: cpuRate,
81+
FillRate: cpuRate,
82+
BurstLimit: options.BurstLimit,
8183
},
8284
},
8385
IoRead: &rmpb.TokenBucket{
8486
Settings: &rmpb.TokenLimitSettings{
85-
FillRate: ioReadRate,
87+
FillRate: ioReadRate,
88+
BurstLimit: options.BurstLimit,
8689
},
8790
},
8891
IoWrite: &rmpb.TokenBucket{
8992
Settings: &rmpb.TokenLimitSettings{
90-
FillRate: ioWriteRate,
93+
FillRate: ioWriteRate,
94+
BurstLimit: options.BurstLimit,
9195
},
9296
},
9397
}

parser/ast/ddl.go

+6
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,7 @@ type ResourceGroupOption struct {
21032103
Tp ResourceUnitType
21042104
StrValue string
21052105
UintValue uint64
2106+
BoolValue bool
21062107
}
21072108

21082109
type ResourceUnitType int
@@ -2114,6 +2115,9 @@ const (
21142115
ResourceUnitCPU
21152116
ResourceUnitIOReadBandwidth
21162117
ResourceUnitIOWriteBandwidth
2118+
2119+
// Options
2120+
ResourceBurstableOpiton
21172121
)
21182122

21192123
func (n *ResourceGroupOption) Restore(ctx *format.RestoreCtx) error {
@@ -2138,6 +2142,8 @@ func (n *ResourceGroupOption) Restore(ctx *format.RestoreCtx) error {
21382142
ctx.WriteKeyWord("IO_WRITE_BANDWIDTH ")
21392143
ctx.WritePlain("= ")
21402144
ctx.WriteString(n.StrValue)
2145+
case ResourceBurstableOpiton:
2146+
ctx.WriteKeyWord("BURSTABLE")
21412147
default:
21422148
return errors.Errorf("invalid PlacementOption: %d", n.Tp)
21432149
}

parser/misc.go

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ var tokenMap = map[string]int{
196196
"BTREE": btree,
197197
"BUCKETS": buckets,
198198
"BUILTINS": builtins,
199+
"BURSTABLE": burstable,
199200
"BY": by,
200201
"BYTE": byteType,
201202
"CACHE": cache,

parser/model/model.go

+5
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,7 @@ type ResourceGroupSettings struct {
18501850
CPULimiter string `json:"cpu_limit"`
18511851
IOReadBandwidth string `json:"io_read_bandwidth"`
18521852
IOWriteBandwidth string `json:"io_write_bandwidth"`
1853+
BurstLimit int64 `json:"burst_limit"`
18531854
}
18541855

18551856
func (p *ResourceGroupSettings) String() string {
@@ -1866,6 +1867,10 @@ func (p *ResourceGroupSettings) String() string {
18661867
if len(p.IOWriteBandwidth) > 0 {
18671868
writeSettingStringToBuilder(sb, "IO_WRITE_BANDWIDTH", p.IOWriteBandwidth)
18681869
}
1870+
// Once burst limit is negative, meaning allow burst with unlimit.
1871+
if p.BurstLimit < 0 {
1872+
writeSettingItemToBuilder(sb, "BURSTABLE")
1873+
}
18691874
return sb.String()
18701875
}
18711876

0 commit comments

Comments
 (0)