Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource_group: supports burstable for resource group #40925

Merged
merged 8 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3034,7 +3034,7 @@ func SetDirectPlacementOpt(placementSettings *model.PlacementSettings, placement
}

// SetDirectResourceGroupUnit tries to set the ResourceGroupSettings.
func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettings, typ ast.ResourceUnitType, stringVal string, uintVal uint64) error {
func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettings, typ ast.ResourceUnitType, stringVal string, uintVal uint64, boolValue bool) error {
switch typ {
case ast.ResourceRURate:
resourceGroupSettings.RURate = uintVal
Expand All @@ -3044,6 +3044,16 @@ func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettin
resourceGroupSettings.IOReadBandwidth = stringVal
case ast.ResourceUnitIOWriteBandwidth:
resourceGroupSettings.IOWriteBandwidth = stringVal
case ast.ResourceBurstableOpiton:
// Some about BurstLimit(b):
// - If b == 0, that means the limiter is unlimited capacity. default use in resource controller (burst with a rate within a unlimited capacity).
// - 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).
// - If b > 0, that means the limiter is limited capacity. (current not used).
limit := int64(0)
if boolValue {
limit = -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the different between -1 and 0?

Copy link
Member Author

@nolouch nolouch Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments, it's not by convention:)

}
resourceGroupSettings.BurstLimit = limit
default:
return errors.Trace(errors.New("unknown resource unit type"))
}
Expand Down Expand Up @@ -7610,7 +7620,7 @@ func (d *ddl) CreateResourceGroup(ctx sessionctx.Context, stmt *ast.CreateResour
groupName := stmt.ResourceGroupName
groupInfo.Name = groupName
for _, opt := range stmt.ResourceGroupOptionList {
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue)
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue, opt.BoolValue)
if err != nil {
return err
}
Expand Down Expand Up @@ -7697,7 +7707,7 @@ func (d *ddl) DropResourceGroup(ctx sessionctx.Context, stmt *ast.DropResourceGr
func buildResourceGroup(oldGroup *model.ResourceGroupInfo, options []*ast.ResourceGroupOption) (*model.ResourceGroupInfo, error) {
groupInfo := &model.ResourceGroupInfo{Name: oldGroup.Name, ID: oldGroup.ID, ResourceGroupSettings: &model.ResourceGroupSettings{}}
for _, opt := range options {
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue)
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue, opt.BoolValue)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion ddl/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ func TestResourceGroupBasic(t *testing.T) {

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

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

tk.MustExec("alter resource group if exists not_exists RU_PER_SEC=2000")
// Check warning message
Expand Down
12 changes: 8 additions & 4 deletions ddl/resourcegroup/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
group.RUSettings = &rmpb.GroupRequestUnitSettings{
RU: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: options.RURate,
FillRate: options.RURate,
BurstLimit: options.BurstLimit,
},
},
}
Expand Down Expand Up @@ -77,17 +78,20 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
group.RawResourceSettings = &rmpb.GroupRawResourceSettings{
Cpu: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: cpuRate,
FillRate: cpuRate,
BurstLimit: options.BurstLimit,
},
},
IoRead: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: ioReadRate,
FillRate: ioReadRate,
BurstLimit: options.BurstLimit,
},
},
IoWrite: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: ioWriteRate,
FillRate: ioWriteRate,
BurstLimit: options.BurstLimit,
},
},
}
Expand Down
6 changes: 6 additions & 0 deletions parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,7 @@ type ResourceGroupOption struct {
Tp ResourceUnitType
StrValue string
UintValue uint64
BoolValue bool
}

type ResourceUnitType int
Expand All @@ -2114,6 +2115,9 @@ const (
ResourceUnitCPU
ResourceUnitIOReadBandwidth
ResourceUnitIOWriteBandwidth

// Options
ResourceBurstableOpiton
)

func (n *ResourceGroupOption) Restore(ctx *format.RestoreCtx) error {
Expand All @@ -2138,6 +2142,8 @@ func (n *ResourceGroupOption) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("IO_WRITE_BANDWIDTH ")
ctx.WritePlain("= ")
ctx.WriteString(n.StrValue)
case ResourceBurstableOpiton:
ctx.WriteKeyWord("BURSTABLE")
default:
return errors.Errorf("invalid PlacementOption: %d", n.Tp)
}
Expand Down
1 change: 1 addition & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ var tokenMap = map[string]int{
"BTREE": btree,
"BUCKETS": buckets,
"BUILTINS": builtins,
"BURSTABLE": burstable,
"BY": by,
"BYTE": byteType,
"CACHE": cache,
Expand Down
5 changes: 5 additions & 0 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,7 @@ type ResourceGroupSettings struct {
CPULimiter string `json:"cpu_limit"`
IOReadBandwidth string `json:"io_read_bandwidth"`
IOWriteBandwidth string `json:"io_write_bandwidth"`
BurstLimit int64 `json:"burst_limit"`
}

func (p *ResourceGroupSettings) String() string {
Expand All @@ -1866,6 +1867,10 @@ func (p *ResourceGroupSettings) String() string {
if len(p.IOWriteBandwidth) > 0 {
writeSettingStringToBuilder(sb, "IO_WRITE_BANDWIDTH", p.IOWriteBandwidth)
}
// Once burst limit is negative, meaning allow burst with unlimit.
if p.BurstLimit < 0 {
writeSettingItemToBuilder(sb, "BURSTABLE")
}
return sb.String()
}

Expand Down
Loading