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

placement: give default 2 followers for non-sugar syntax #31000

Merged
merged 6 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
42 changes: 17 additions & 25 deletions ddl/placement/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,24 @@ func NewBundleFromConstraintsOptions(options *model.PlacementSettings) (*Bundle,
return nil, fmt.Errorf("%w: LeaderConstraints conflicts with Constraints", err)
}
}
if len(LeaderConstraints) > 0 {
Rules = append(Rules, NewRule(Leader, 1, LeaderConstraints))
} else if followerCount == 0 {
return nil, fmt.Errorf("%w: you must at least provide common/leader constraints, or set some followers", ErrInvalidPlacementOptions)
}
Rules = append(Rules, NewRule(Leader, 1, LeaderConstraints))

if followerCount > 0 {
// if user did not specify leader, add one
if len(LeaderConstraints) == 0 {
Rules = append(Rules, NewRule(Leader, 1, NewConstraintsDirect()))
}
if followerCount == 0 {
return nil, fmt.Errorf("%w: you must set some followers", ErrInvalidPlacementOptions)
}

FollowerRules, err := NewRules(Voter, followerCount, followerConstraints)
if err != nil {
return nil, fmt.Errorf("%w: invalid FollowerConstraints", err)
}
for _, rule := range FollowerRules {
for _, cnst := range CommonConstraints {
if err := rule.Constraints.Add(cnst); err != nil {
return nil, fmt.Errorf("%w: FollowerConstraints conflicts with Constraints", err)
}
FollowerRules, err := NewRules(Voter, followerCount, followerConstraints)
if err != nil {
return nil, fmt.Errorf("%w: invalid FollowerConstraints", err)
}
for _, rule := range FollowerRules {
for _, cnst := range CommonConstraints {
if err := rule.Constraints.Add(cnst); err != nil {
return nil, fmt.Errorf("%w: FollowerConstraints conflicts with Constraints", err)
}
}
Rules = append(Rules, FollowerRules...)
} else if followerConstraints != "" {
return nil, fmt.Errorf("%w: specify follower constraints without specify how many followers to be placed", ErrInvalidPlacementOptions)
}
Rules = append(Rules, FollowerRules...)

if learnerCount > 0 {
LearnerRules, err := NewRules(Learner, learnerCount, learnerConstraints)
Expand Down Expand Up @@ -154,9 +145,6 @@ func NewBundleFromSugarOptions(options *model.PlacementSettings) (*Bundle, error
}

followers := options.Followers
if followers == 0 {
followers = 2
}
schedule := options.Schedule

primaryIndex := 0
Expand Down Expand Up @@ -217,6 +205,10 @@ func newBundleFromOptions(options *model.PlacementSettings) (bundle *Bundle, err
isSyntaxSugar = false
}

if options.Followers == 0 {
xhebox marked this conversation as resolved.
Show resolved Hide resolved
options.Followers = 2
}

if isSyntaxSugar {
bundle, err = NewBundleFromSugarOptions(options)
} else {
Expand Down
5 changes: 4 additions & 1 deletion ddl/placement/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,10 @@ func (s *testBundleSuite) TestNewBundleFromOptions(c *C) {
LeaderConstraints: "[+region=as]",
FollowerConstraints: "[-region=us]",
},
err: ErrInvalidPlacementOptions,
output: []*Rule{
NewRule(Leader, 1, NewConstraintsDirect(NewConstraintDirect("region", In, "as"))),
NewRule(Voter, 2, NewConstraintsDirect(NewConstraintDirect("region", NotIn, "us"))),
},
})

tests = append(tests, TestCase{
Expand Down