From 4cd0155233fcbbee7a092f012211003434dbfa0a Mon Sep 17 00:00:00 2001 From: sylzd Date: Tue, 14 Dec 2021 19:39:27 +0800 Subject: [PATCH 1/3] return error if larger than 8 --- ddl/placement/bundle.go | 7 +++++++ ddl/placement_policy_test.go | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/ddl/placement/bundle.go b/ddl/placement/bundle.go index 9c493dccdf619..12008dfa9eccb 100644 --- a/ddl/placement/bundle.go +++ b/ddl/placement/bundle.go @@ -207,6 +207,13 @@ 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) + } + if options.Followers > uint64(0) && int(options.Followers) % 2 != 0 { + + } + // 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 f4c4eb54e69b3..4d1a3897316fa 100644 --- a/ddl/placement_policy_test.go +++ b/ddl/placement_policy_test.go @@ -48,6 +48,27 @@ func clearAllBundles(c *C) { c.Assert(err, IsNil) } +func (s *testDBSuite6) TestPlacementFollowers(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + + 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") + +// tk.MustQuery("show warnings").Check(testkit.Rows("Note 8238 Placement policy 'X' already exists")) +} + func (s *testDBSuite6) TestPlacementPolicy(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") From d3b60f660ff8feb9fb8d277afee5e3b7b65ccbac Mon Sep 17 00:00:00 2001 From: sylzd Date: Tue, 14 Dec 2021 20:13:11 +0800 Subject: [PATCH 2/3] fix --- ddl/placement/bundle.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/ddl/placement/bundle.go b/ddl/placement/bundle.go index 12008dfa9eccb..fe160c7653565 100644 --- a/ddl/placement/bundle.go +++ b/ddl/placement/bundle.go @@ -210,9 +210,6 @@ func newBundleFromOptions(options *model.PlacementSettings) (bundle *Bundle, err if options.Followers > uint64(8) { return nil, fmt.Errorf("%w: followers should be less than or equal to 8: %d", ErrInvalidPlacementOptions, options.Followers) } - if options.Followers > uint64(0) && int(options.Followers) % 2 != 0 { - - } // always prefer the sugar syntax, which gives better schedule results most of the time isSyntaxSugar := true From 21ed19d7a8166db786f108e08477c0618b977077 Mon Sep 17 00:00:00 2001 From: sylzd Date: Tue, 14 Dec 2021 20:39:17 +0800 Subject: [PATCH 3/3] clean test --- ddl/placement_policy_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ddl/placement_policy_test.go b/ddl/placement_policy_test.go index eb64a9463863c..94a90692dcdf1 100644 --- a/ddl/placement_policy_test.go +++ b/ddl/placement_policy_test.go @@ -206,6 +206,8 @@ func (s *testDBSuite6) TestPlacementPolicy(c *C) { 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")