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

ddl: handle the incorrect number of placement followers #30715

Merged
merged 5 commits into from
Dec 16, 2021
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
4 changes: 4 additions & 0 deletions ddl/placement/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ func newBundleFromOptions(options *model.PlacementSettings) (bundle *Bundle, err
return nil, fmt.Errorf("%w: options can not be nil", ErrInvalidPlacementOptions)
}

if options.Followers > uint64(8) {
AilinKid marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("%w: followers should be less than or equal to 8: %d", ErrInvalidPlacementOptions, options.Followers)
}

// always prefer the sugar syntax, which gives better schedule results most of the time
isSyntaxSugar := true
if len(options.LeaderConstraints) > 0 || len(options.LearnerConstraints) > 0 || len(options.FollowerConstraints) > 0 || len(options.Constraints) > 0 || options.Learners > 0 {
Expand Down
21 changes: 21 additions & 0 deletions ddl/placement_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,27 @@ func (s *testDBSuite6) TestPlacementPolicy(c *C) {
// TODO: privilege check & constraint syntax check.
}

func (s *testDBSuite6) TestPlacementFollowers(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
defer tk.MustExec("drop table if exists t1")
defer tk.MustExec("drop placement policy if exists x")

tk.MustExec("drop placement policy if exists x")
tk.MustGetErrMsg("create placement policy x FOLLOWERS=99", "invalid placement option: followers should be less than or equal to 8: 99")

tk.MustExec("drop placement policy if exists x")
tk.MustExec("create placement policy x FOLLOWERS=4")
tk.MustGetErrMsg("alter placement policy x FOLLOWERS=99", "invalid placement option: followers should be less than or equal to 8: 99")

tk.MustExec("drop table if exists t1")
tk.MustGetErrMsg("create table t1 (a int) followers=99;", "invalid placement option: followers should be less than or equal to 8: 99")

tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1 (a int) followers=4;")
tk.MustGetErrMsg("alter table t1 followers=99;", "invalid placement option: followers should be less than or equal to 8: 99")
}

func testGetPolicyByIDFromMeta(c *C, store kv.Storage, policyID int64) *model.PolicyInfo {
var (
policyInfo *model.PolicyInfo
Expand Down