diff --git a/ddl/placement/bundle.go b/ddl/placement/bundle.go index 9c493dccdf619..fe160c7653565 100644 --- a/ddl/placement/bundle.go +++ b/ddl/placement/bundle.go @@ -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 { diff --git a/ddl/placement_policy_test.go b/ddl/placement_policy_test.go index 22c0a23c09d9f..1cdb8da5d5661 100644 --- a/ddl/placement_policy_test.go +++ b/ddl/placement_policy_test.go @@ -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