Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
  • Loading branch information
CabinfeverB committed Feb 8, 2023
1 parent 8c3f5ff commit ed33da0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 5 additions & 7 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7615,14 +7615,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 @@ -7711,6 +7708,7 @@ func buildResourceGroup(oldGroup *model.ResourceGroupInfo, options []*ast.Resour
return nil, err
}
}
groupInfo.ResourceGroupSettings.Adjust()
return groupInfo, nil
}

Expand Down
6 changes: 1 addition & 5 deletions ddl/resourcegroup/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
}
if options.RURate > 0 {
group.Mode = rmpb.GroupMode_RUMode
burstLimit := options.BurstLimit
if burstLimit >= 0 {
burstLimit = int64(options.RURate)
}
group.RUSettings = &rmpb.GroupRequestUnitSettings{
RU: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: options.RURate,
BurstLimit: burstLimit,
BurstLimit: options.BurstLimit,
},
},
}
Expand Down
8 changes: 8 additions & 0 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,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

0 comments on commit ed33da0

Please sign in to comment.