From 172a89c7a26474f9029a16928062b39ddc43c3c0 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Mon, 24 May 2021 18:27:33 +0800 Subject: [PATCH] checker: fix the operator priority (#3694) * fix the operator priority Signed-off-by: Ryan Leung * add tests Signed-off-by: Ryan Leung Co-authored-by: Ti Chi Robot --- server/schedule/checker/rule_checker.go | 14 ++++++++++++-- server/schedule/checker/rule_checker_test.go | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/schedule/checker/rule_checker.go b/server/schedule/checker/rule_checker.go index fa9348bbda7..0fb3ad7d3f0 100644 --- a/server/schedule/checker/rule_checker.go +++ b/server/schedule/checker/rule_checker.go @@ -135,7 +135,12 @@ func (c *RuleChecker) addRulePeer(region *core.RegionInfo, rf *placement.RuleFit return nil, errors.New("no store to add peer") } peer := &metapb.Peer{StoreId: store, Role: rf.Rule.Role.MetaPeerRole()} - return operator.CreateAddPeerOperator("add-rule-peer", c.cluster, region, peer, operator.OpReplica) + op, err := operator.CreateAddPeerOperator("add-rule-peer", c.cluster, region, peer, operator.OpReplica) + if err != nil { + return nil, err + } + op.SetPriorityLevel(core.HighPriority) + return op, nil } func (c *RuleChecker) replaceRulePeer(region *core.RegionInfo, rf *placement.RuleFit, peer *metapb.Peer, status string) (*operator.Operator, error) { @@ -147,7 +152,12 @@ func (c *RuleChecker) replaceRulePeer(region *core.RegionInfo, rf *placement.Rul return nil, errors.New("no store to replace peer") } newPeer := &metapb.Peer{StoreId: store, Role: rf.Rule.Role.MetaPeerRole()} - return operator.CreateMovePeerOperator("replace-rule-"+status+"-peer", c.cluster, region, operator.OpReplica, peer.StoreId, newPeer) + op, err := operator.CreateMovePeerOperator("replace-rule-"+status+"-peer", c.cluster, region, operator.OpReplica, peer.StoreId, newPeer) + if err != nil { + return nil, err + } + op.SetPriorityLevel(core.HighPriority) + return op, nil } func (c *RuleChecker) fixLooseMatchPeer(region *core.RegionInfo, fit *placement.RegionFit, rf *placement.RuleFit, peer *metapb.Peer) (*operator.Operator, error) { diff --git a/server/schedule/checker/rule_checker_test.go b/server/schedule/checker/rule_checker_test.go index c615a0b55e1..a16a15c690b 100644 --- a/server/schedule/checker/rule_checker_test.go +++ b/server/schedule/checker/rule_checker_test.go @@ -85,6 +85,7 @@ func (s *testRuleCheckerSuite) TestAddRulePeer(c *C) { op := s.rc.Check(s.cluster.GetRegion(1)) c.Assert(op, NotNil) c.Assert(op.Desc(), Equals, "add-rule-peer") + c.Assert(op.GetPriorityLevel(), Equals, core.HighPriority) c.Assert(op.Step(0).(operator.AddLearner).ToStore, Equals, uint64(3)) } @@ -137,6 +138,7 @@ func (s *testRuleCheckerSuite) TestFixPeer(c *C) { op = s.rc.Check(r) c.Assert(op, NotNil) c.Assert(op.Desc(), Equals, "replace-rule-down-peer") + c.Assert(op.GetPriorityLevel(), Equals, core.HighPriority) var add operator.AddLearner c.Assert(op.Step(0), FitsTypeOf, add) s.cluster.SetStoreUp(2) @@ -144,6 +146,7 @@ func (s *testRuleCheckerSuite) TestFixPeer(c *C) { op = s.rc.Check(s.cluster.GetRegion(1)) c.Assert(op, NotNil) c.Assert(op.Desc(), Equals, "replace-rule-offline-peer") + c.Assert(op.GetPriorityLevel(), Equals, core.HighPriority) c.Assert(op.Step(0), FitsTypeOf, add) }