Skip to content

Commit

Permalink
ddl: handle the incorrect number of placement followers (#30715)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylzd authored Dec 16, 2021
1 parent ad740a6 commit c75ea85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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) {
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

0 comments on commit c75ea85

Please sign in to comment.