Skip to content

Commit 096edb5

Browse files
committed
resource_group: supports burstable for resource group
Signed-off-by: nolouch <nolouch@gmail.com>
1 parent 1e0956d commit 096edb5

File tree

12 files changed

+7829
-7785
lines changed

12 files changed

+7829
-7785
lines changed

DEPS.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -3980,8 +3980,8 @@ def go_deps():
39803980
name = "com_github_tikv_pd",
39813981
build_file_proto_mode = "disable",
39823982
importpath = "github.com/tikv/pd",
3983-
sum = "h1:cj3bhdIBJcLL2304EDEmd3eX+r73+hbGSYRFn/APiDU=",
3984-
version = "v1.1.0-beta.0.20230119114149-402c2bfee2f3",
3983+
sum = "h1:bDwwSWvUNT2aoUgTzZve4ngOx20y3BOqNd8asu2ZGio=",
3984+
version = "v1.1.0-beta.0.20230131135954-872c73d8a930",
39853985
)
39863986

39873987
go_repository(

ddl/ddl_api.go

+10-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.ResourceRRURate:
30403040
resourceGroupSettings.RRURate = uintVal
@@ -3046,6 +3046,13 @@ func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettin
30463046
resourceGroupSettings.IOReadBandwidth = stringVal
30473047
case ast.ResourceUnitIOWriteBandwidth:
30483048
resourceGroupSettings.IOWriteBandwidth = stringVal
3049+
case ast.ResourceBurstableOpiton:
3050+
limit := int64(0)
3051+
if boolValue {
3052+
// negative means no limit within burst setting.
3053+
limit = -1
3054+
}
3055+
resourceGroupSettings.BurstLimit = limit
30493056
default:
30503057
return errors.Trace(errors.New("unknown resource unit type"))
30513058
}
@@ -7612,7 +7619,7 @@ func (d *ddl) CreateResourceGroup(ctx sessionctx.Context, stmt *ast.CreateResour
76127619
groupName := stmt.ResourceGroupName
76137620
groupInfo.Name = groupName
76147621
for _, opt := range stmt.ResourceGroupOptionList {
7615-
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue)
7622+
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue, opt.BoolValue)
76167623
if err != nil {
76177624
return err
76187625
}
@@ -7695,7 +7702,7 @@ func (d *ddl) DropResourceGroup(ctx sessionctx.Context, stmt *ast.DropResourceGr
76957702
func buildResourceGroup(oldGroup *model.ResourceGroupInfo, options []*ast.ResourceGroupOption) (*model.ResourceGroupInfo, error) {
76967703
groupInfo := &model.ResourceGroupInfo{Name: oldGroup.Name, ID: oldGroup.ID, ResourceGroupSettings: &model.ResourceGroupSettings{}}
76977704
for _, opt := range options {
7698-
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue)
7705+
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue, opt.BoolValue)
76997706
if err != nil {
77007707
return nil, err
77017708
}

ddl/resource_group_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ func TestResourceGroupBasic(t *testing.T) {
8686

8787
tk.MustExec("alter resource group x " +
8888
"RRU_PER_SEC=2000 " +
89-
"WRU_PER_SEC=3000")
89+
"WRU_PER_SEC=3000 " +
90+
"BURSTABLE")
9091
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
9192
re.Equal(uint64(2000), g.RRURate)
9293
re.Equal(uint64(3000), g.WRURate)
94+
re.Equal(int64(-1), g.BurstLimit)
9395

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

ddl/resourcegroup/group.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
4141
group.RUSettings = &rmpb.GroupRequestUnitSettings{
4242
RRU: &rmpb.TokenBucket{
4343
Settings: &rmpb.TokenLimitSettings{
44-
FillRate: options.RRURate,
44+
FillRate: options.RRURate,
45+
BurstLimit: options.BurstLimit,
4546
},
4647
},
4748
WRU: &rmpb.TokenBucket{
4849
Settings: &rmpb.TokenLimitSettings{
49-
FillRate: options.WRURate,
50+
FillRate: options.WRURate,
51+
BurstLimit: options.BurstLimit,
5052
},
5153
},
5254
}
@@ -82,17 +84,20 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
8284
group.RawResourceSettings = &rmpb.GroupRawResourceSettings{
8385
Cpu: &rmpb.TokenBucket{
8486
Settings: &rmpb.TokenLimitSettings{
85-
FillRate: cpuRate,
87+
FillRate: cpuRate,
88+
BurstLimit: options.BurstLimit,
8689
},
8790
},
8891
IoRead: &rmpb.TokenBucket{
8992
Settings: &rmpb.TokenLimitSettings{
90-
FillRate: ioReadRate,
93+
FillRate: ioReadRate,
94+
BurstLimit: options.BurstLimit,
9195
},
9296
},
9397
IoWrite: &rmpb.TokenBucket{
9498
Settings: &rmpb.TokenLimitSettings{
95-
FillRate: ioWriteRate,
99+
FillRate: ioWriteRate,
100+
BurstLimit: options.BurstLimit,
96101
},
97102
},
98103
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ require (
9191
github.com/tdakkota/asciicheck v0.1.1
9292
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
9393
github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234
94-
github.com/tikv/pd v1.1.0-beta.0.20230119114149-402c2bfee2f3
94+
github.com/tikv/pd v1.1.0-beta.0.20230131135954-872c73d8a930
9595
github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93
9696
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144
9797
github.com/twmb/murmur3 v1.1.3

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,8 @@ github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW
12771277
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
12781278
github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234 h1:2BmijiUk1Hcv0z58DVk4ypwaNmgutzLc2YJm0SHPEWE=
12791279
github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234/go.mod h1:jc7J2EbNeVvU6eXmB50wAGrTPyJwdi+0ENccMXMFSpw=
1280-
github.com/tikv/pd v1.1.0-beta.0.20230119114149-402c2bfee2f3 h1:cj3bhdIBJcLL2304EDEmd3eX+r73+hbGSYRFn/APiDU=
1281-
github.com/tikv/pd v1.1.0-beta.0.20230119114149-402c2bfee2f3/go.mod h1:IFQZ85uu1438yp7Tb0xCgvw/BdSPReB9zcJsxXbyTP4=
1280+
github.com/tikv/pd v1.1.0-beta.0.20230131135954-872c73d8a930 h1:bDwwSWvUNT2aoUgTzZve4ngOx20y3BOqNd8asu2ZGio=
1281+
github.com/tikv/pd v1.1.0-beta.0.20230131135954-872c73d8a930/go.mod h1:IFQZ85uu1438yp7Tb0xCgvw/BdSPReB9zcJsxXbyTP4=
12821282
github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93 h1:KK5bx0KLcpYUCnuQ06THPYT6QdAMfvwAtRQ0saVGD7k=
12831283
github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93/go.mod h1:NrbwVp9afaCmJjJEwFNtEQWfCChAW1ndnwjteHHS+d0=
12841284
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 h1:kl4KhGNsJIbDHS9/4U9yQo1UcPQM0kOMJHn29EoH/Ro=

parser/ast/ddl.go

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

21082109
type ResourceUnitType int
21092110

21102111
const (
2112+
// RU mode
21112113
ResourceRRURate ResourceUnitType = iota
21122114
ResourceWRURate
2113-
// Native mode
2115+
2116+
// Raw mode
21142117
ResourceUnitCPU
21152118
ResourceUnitIOReadBandwidth
21162119
ResourceUnitIOWriteBandwidth
2120+
2121+
// Options
2122+
ResourceBurstableOpiton
21172123
)
21182124

21192125
func (n *ResourceGroupOption) Restore(ctx *format.RestoreCtx) error {
@@ -2142,6 +2148,8 @@ func (n *ResourceGroupOption) Restore(ctx *format.RestoreCtx) error {
21422148
ctx.WriteKeyWord("IO_WRITE_BANDWIDTH ")
21432149
ctx.WritePlain("= ")
21442150
ctx.WriteString(n.StrValue)
2151+
case ResourceBurstableOpiton:
2152+
ctx.WriteKeyWord("BURSTABLE ")
21452153
default:
21462154
return errors.Errorf("invalid PlacementOption: %d", n.Tp)
21472155
}

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
@@ -1851,6 +1851,7 @@ type ResourceGroupSettings struct {
18511851
CPULimiter string `json:"cpu_limit"`
18521852
IOReadBandwidth string `json:"io_read_bandwidth"`
18531853
IOWriteBandwidth string `json:"io_write_bandwidth"`
1854+
BurstLimit int64 `json:"burst_limit"`
18541855
}
18551856

18561857
func (p *ResourceGroupSettings) String() string {
@@ -1870,6 +1871,10 @@ func (p *ResourceGroupSettings) String() string {
18701871
if len(p.IOWriteBandwidth) > 0 {
18711872
writeSettingStringToBuilder(sb, "IO_WRITE_BANDWIDTH", p.IOWriteBandwidth)
18721873
}
1874+
// Once burst limit is negative, meaning allow burst with unlimit.
1875+
if p.BurstLimit < 0 {
1876+
writeSettingItemToBuilder(sb, "BURSTABLE")
1877+
}
18731878
return sb.String()
18741879
}
18751880

0 commit comments

Comments
 (0)