Skip to content

Commit

Permalink
move tidy to constructors: NewBundleFromOptions
Browse files Browse the repository at this point in the history
Signed-off-by: ailinkid <314806019@qq.com>
  • Loading branch information
AilinKid committed Oct 8, 2021
1 parent 247a8df commit ad907f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 18 additions & 3 deletions ddl/placement/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func NewBundleFromSugarOptions(options *model.PlacementSettings) (*Bundle, error
}

// NewBundleFromOptions will transform options into the bundle.
func NewBundleFromOptions(options *model.PlacementSettings) (*Bundle, error) {
func NewBundleFromOptions(options *model.PlacementSettings) (bundle *Bundle, err error) {
var isSyntaxSugar bool

if options == nil {
Expand All @@ -200,9 +200,24 @@ func NewBundleFromOptions(options *model.PlacementSettings) (*Bundle, error) {
}

if isSyntaxSugar {
return NewBundleFromSugarOptions(options)
bundle, err = NewBundleFromSugarOptions(options)
if err != nil {
return nil, err
}
} else {
bundle, err = NewBundleFromConstraintsOptions(options)
if err != nil {
return nil, err
}
}
if bundle == nil {
return nil, nil
}
err = bundle.Tidy()
if err != nil {
return nil, err
}
return NewBundleFromConstraintsOptions(options)
return bundle, err
}

// ApplyPlacementSpec will apply actions defined in PlacementSpec to the bundle.
Expand Down
4 changes: 0 additions & 4 deletions ddl/placement_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ func onAlterPlacementPolicy(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64,
if err != nil {
return ver, errors.Trace(err)
}
err = bundle.Tidy()
if err != nil {
return ver, errors.Trace(err)
}
// Do the http request only when the rules is existed.
bundles := make([]*placement.Bundle, 0, len(tblInfos)+len(partIDs))
// Reset bundle for tables (including the default rule for partition).
Expand Down

0 comments on commit ad907f3

Please sign in to comment.