Skip to content
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
12 changes: 5 additions & 7 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7617,14 +7617,11 @@ func checkIgnorePlacementDDL(ctx sessionctx.Context) bool {

// AddResourceGroup implements the DDL interface, creates a resource group.
func (d *ddl) AddResourceGroup(ctx sessionctx.Context, stmt *ast.CreateResourceGroupStmt) (err error) {
groupInfo := &model.ResourceGroupInfo{ResourceGroupSettings: &model.ResourceGroupSettings{}}
groupName := stmt.ResourceGroupName
groupInfo.Name = groupName
for _, opt := range stmt.ResourceGroupOptionList {
err := SetDirectResourceGroupUnit(groupInfo.ResourceGroupSettings, opt.Tp, opt.StrValue, opt.UintValue, opt.BoolValue)
if err != nil {
return err
}
groupInfo := &model.ResourceGroupInfo{Name: groupName, ResourceGroupSettings: &model.ResourceGroupSettings{}}
groupInfo, err = buildResourceGroup(groupInfo, stmt.ResourceGroupOptionList)
if err != nil {
return err
}

if _, ok := d.GetInfoSchemaWithInterceptor(ctx).ResourceGroupByName(groupName); ok {
Expand Down Expand Up @@ -7713,6 +7710,7 @@ func buildResourceGroup(oldGroup *model.ResourceGroupInfo, options []*ast.Resour
return nil, err
}
}
groupInfo.ResourceGroupSettings.Adjust()
return groupInfo, nil
}

Expand Down
18 changes: 11 additions & 7 deletions ddl/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestResourceGroupBasic(t *testing.T) {
re.Equal(uint64(2000), g.RURate)
re.Equal(int64(-1), g.BurstLimit)

tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 2000 0 YES"))
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 2000 YES"))

tk.MustExec("drop resource group x")
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
Expand All @@ -104,7 +104,7 @@ func TestResourceGroupBasic(t *testing.T) {
require.Equal(t, "y", groupInfo.Name.L)
require.Equal(t, groupID, groupInfo.ID)
require.Equal(t, uint64(4000), groupInfo.RURate)
require.Equal(t, int64(0), groupInfo.BurstLimit)
require.Equal(t, int64(4000), groupInfo.BurstLimit)
}
g = testResourceGroupNameFromIS(t, tk.Session(), "y")
checkFunc(g)
Expand All @@ -126,25 +126,29 @@ func TestResourceGroupBasic(t *testing.T) {
tk.MustContainErrMsg("create resource group x ru_per_sec=1000 ru_per_sec=200, ru_per_sec=300", "Dupliated options specified")
tk.MustGetErrCode("create resource group x burstable, burstable", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x burstable, burstable", "Dupliated options specified")
tk.MustGetErrCode("create resource group x ru_per_sec=1000, burstable, burstable", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x ru_per_sec=1000, burstable, burstable", "Dupliated options specified")
tk.MustGetErrCode("create resource group x burstable, ru_per_sec=1000, burstable", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x burstable, ru_per_sec=1000, burstable", "Dupliated options specified")
groups, err := infosync.ListResourceGroups(context.TODO())
require.Equal(t, 0, len(groups))
require.NoError(t, err)

// Check information schema table information_schema.resource_groups
tk.MustExec("create resource group x RU_PER_SEC=1000")
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 1000 0 NO"))
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 1000 NO"))
tk.MustExec("alter resource group x RU_PER_SEC=2000 BURSTABLE")
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 2000 0 YES"))
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 2000 YES"))
tk.MustExec("alter resource group x BURSTABLE RU_PER_SEC=3000")
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 3000 0 YES"))
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 3000 YES"))
tk.MustQuery("show create resource group x").Check(testkit.Rows("x CREATE RESOURCE GROUP `x` RU_PER_SEC=3000 BURSTABLE"))

tk.MustExec("create resource group y BURSTABLE RU_PER_SEC=2000")
tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 2000 0 YES"))
tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 2000 YES"))
tk.MustQuery("show create resource group y").Check(testkit.Rows("y CREATE RESOURCE GROUP `y` RU_PER_SEC=2000 BURSTABLE"))

tk.MustExec("alter resource group y RU_PER_SEC=4000 BURSTABLE")
tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 4000 0 YES"))
tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 4000 YES"))
tk.MustQuery("show create resource group y").Check(testkit.Rows("y CREATE RESOURCE GROUP `y` RU_PER_SEC=4000 BURSTABLE"))

tk.MustQuery("select count(*) from information_schema.resource_groups").Check(testkit.Rows("2"))
Expand Down
2 changes: 0 additions & 2 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3406,7 +3406,6 @@ func (e *memtableRetriever) setDataFromResourceGroups() error {
row := types.MakeDatums(
group.Name,
group.RUSettings.RU.Settings.FillRate,
uint64(group.RUSettings.RU.Tokens),
burstable,
)
rows = append(rows, row)
Expand All @@ -3416,7 +3415,6 @@ func (e *memtableRetriever) setDataFromResourceGroups() error {
group.Name,
nil,
nil,
nil,
)
rows = append(rows, row)
}
Expand Down
1 change: 0 additions & 1 deletion infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,6 @@ var tableMemoryUsageOpsHistoryCols = []columnInfo{
var tableResourceGroupsCols = []columnInfo{
{name: "NAME", tp: mysql.TypeVarchar, size: resourcegroup.MaxGroupNameLength, flag: mysql.NotNullFlag},
{name: "RU_PER_SEC", tp: mysql.TypeLonglong, size: 21},
{name: "RU_TOKENS", tp: mysql.TypeLonglong, size: 21},
{name: "BURSTABLE", tp: mysql.TypeVarchar, size: 3},
}

Expand Down
8 changes: 8 additions & 0 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,14 @@ func (p *ResourceGroupSettings) String() string {
return sb.String()
}

// Adjust adjusts the resource group settings.
func (p *ResourceGroupSettings) Adjust() {
// Curretly we only support ru_per_sec sytanx, so BurstLimit(capicity) is always same as ru_per_sec.
if p.BurstLimit == 0 {
p.BurstLimit = int64(p.RURate)
}
}

// Clone clones the resource group settings.
func (p *ResourceGroupSettings) Clone() *ResourceGroupSettings {
cloned := *p
Expand Down
10 changes: 6 additions & 4 deletions parser/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1599,19 +1599,21 @@ ResourceGroupOptionList:
}
| ResourceGroupOptionList DirectResourceGroupOption
{
$$ = append($1.([]*ast.ResourceGroupOption), $2.(*ast.ResourceGroupOption))
if $1.([]*ast.ResourceGroupOption)[0].Tp == $2.(*ast.ResourceGroupOption).Tp {
if $1.([]*ast.ResourceGroupOption)[0].Tp == $2.(*ast.ResourceGroupOption).Tp ||
(len($1.([]*ast.ResourceGroupOption)) > 1 && $1.([]*ast.ResourceGroupOption)[1].Tp == $2.(*ast.ResourceGroupOption).Tp) {
yylex.AppendError(yylex.Errorf("Dupliated options specified"))
return 1
}
$$ = append($1.([]*ast.ResourceGroupOption), $2.(*ast.ResourceGroupOption))
}
| ResourceGroupOptionList ',' DirectResourceGroupOption
{
if $1.([]*ast.ResourceGroupOption)[0].Tp == $3.(*ast.ResourceGroupOption).Tp ||
(len($1.([]*ast.ResourceGroupOption)) > 1 && $1.([]*ast.ResourceGroupOption)[1].Tp == $3.(*ast.ResourceGroupOption).Tp) {
yylex.AppendError(yylex.Errorf("Dupliated options specified"))
return 1
}
$$ = append($1.([]*ast.ResourceGroupOption), $3.(*ast.ResourceGroupOption))
if $1.([]*ast.ResourceGroupOption)[0].Tp == $3.(*ast.ResourceGroupOption).Tp {
yylex.AppendError(yylex.Errorf("Dupliated options specified"))
return 1
}
}

DirectResourceGroupOption:
Expand Down