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 1 commit
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
4 changes: 2 additions & 2 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3980,8 +3980,8 @@ def go_deps():
name = "com_github_tikv_pd",
build_file_proto_mode = "disable",
importpath = "github.com/tikv/pd",
sum = "h1:cj3bhdIBJcLL2304EDEmd3eX+r73+hbGSYRFn/APiDU=",
version = "v1.1.0-beta.0.20230119114149-402c2bfee2f3",
sum = "h1:bDwwSWvUNT2aoUgTzZve4ngOx20y3BOqNd8asu2ZGio=",
version = "v1.1.0-beta.0.20230131135954-872c73d8a930",
)

go_repository(
Expand Down
13 changes: 10 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.ResourceRRURate:
resourceGroupSettings.RRURate = uintVal
Expand All @@ -3046,6 +3046,13 @@ func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettin
resourceGroupSettings.IOReadBandwidth = stringVal
case ast.ResourceUnitIOWriteBandwidth:
resourceGroupSettings.IOWriteBandwidth = stringVal
case ast.ResourceBurstableOpiton:
limit := int64(0)
if boolValue {
// negative means no limit within burst setting.
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 @@ -7612,7 +7619,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 @@ -7695,7 +7702,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
4 changes: 3 additions & 1 deletion ddl/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ func TestResourceGroupBasic(t *testing.T) {

tk.MustExec("alter resource group x " +
"RRU_PER_SEC=2000 " +
"WRU_PER_SEC=3000")
"WRU_PER_SEC=3000 " +
"BURSTABLE")
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
re.Equal(uint64(2000), g.RRURate)
re.Equal(uint64(3000), g.WRURate)
re.Equal(int64(-1), g.BurstLimit)

tk.MustQuery("select * from information_schema.resource_groups where group_name = 'x'").Check(testkit.Rows(strconv.FormatInt(g.ID, 10) + " x 2000 3000"))

Expand Down
15 changes: 10 additions & 5 deletions ddl/resourcegroup/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
group.RUSettings = &rmpb.GroupRequestUnitSettings{
RRU: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: options.RRURate,
FillRate: options.RRURate,
BurstLimit: options.BurstLimit,
},
},
WRU: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: options.WRURate,
FillRate: options.WRURate,
BurstLimit: options.BurstLimit,
},
},
}
Expand Down Expand Up @@ -82,17 +84,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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ require (
github.com/tdakkota/asciicheck v0.1.1
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234
github.com/tikv/pd v1.1.0-beta.0.20230119114149-402c2bfee2f3
github.com/tikv/pd v1.1.0-beta.0.20230131135954-872c73d8a930
github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144
github.com/twmb/murmur3 v1.1.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,8 @@ github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234 h1:2BmijiUk1Hcv0z58DVk4ypwaNmgutzLc2YJm0SHPEWE=
github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234/go.mod h1:jc7J2EbNeVvU6eXmB50wAGrTPyJwdi+0ENccMXMFSpw=
github.com/tikv/pd v1.1.0-beta.0.20230119114149-402c2bfee2f3 h1:cj3bhdIBJcLL2304EDEmd3eX+r73+hbGSYRFn/APiDU=
github.com/tikv/pd v1.1.0-beta.0.20230119114149-402c2bfee2f3/go.mod h1:IFQZ85uu1438yp7Tb0xCgvw/BdSPReB9zcJsxXbyTP4=
github.com/tikv/pd v1.1.0-beta.0.20230131135954-872c73d8a930 h1:bDwwSWvUNT2aoUgTzZve4ngOx20y3BOqNd8asu2ZGio=
github.com/tikv/pd v1.1.0-beta.0.20230131135954-872c73d8a930/go.mod h1:IFQZ85uu1438yp7Tb0xCgvw/BdSPReB9zcJsxXbyTP4=
github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93 h1:KK5bx0KLcpYUCnuQ06THPYT6QdAMfvwAtRQ0saVGD7k=
github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93/go.mod h1:NrbwVp9afaCmJjJEwFNtEQWfCChAW1ndnwjteHHS+d0=
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 h1:kl4KhGNsJIbDHS9/4U9yQo1UcPQM0kOMJHn29EoH/Ro=
Expand Down
10 changes: 9 additions & 1 deletion parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2103,17 +2103,23 @@ type ResourceGroupOption struct {
Tp ResourceUnitType
StrValue string
UintValue uint64
BoolValue bool
}

type ResourceUnitType int

const (
// RU mode
ResourceRRURate ResourceUnitType = iota
ResourceWRURate
// Native mode

// Raw mode
ResourceUnitCPU
ResourceUnitIOReadBandwidth
ResourceUnitIOWriteBandwidth

// Options
ResourceBurstableOpiton
)

func (n *ResourceGroupOption) Restore(ctx *format.RestoreCtx) error {
Expand Down Expand Up @@ -2142,6 +2148,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 @@ -1851,6 +1851,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 @@ -1870,6 +1871,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