From e649fe7afbe2bfa37f0856a3b2ed46c3f2fbae7d Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 6 Jul 2021 20:15:29 +0800 Subject: [PATCH] checker: fix the operator priority (#3694) (#3703) * This is an automated cherry-pick of #3694 Signed-off-by: ti-chi-bot * resolve conflicts Signed-off-by: Ryan Leung Co-authored-by: Ryan Leung --- 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 755d1acd009..3329abdfa0a 100644 --- a/server/schedule/checker/rule_checker.go +++ b/server/schedule/checker/rule_checker.go @@ -124,7 +124,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.GetID(), IsLearner: rf.Rule.Role == placement.Learner} - 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, fit *placement.RegionFit, rf *placement.RuleFit, peer *metapb.Peer, status string) (*operator.Operator, error) { @@ -134,7 +139,12 @@ func (c *RuleChecker) replaceRulePeer(region *core.RegionInfo, fit *placement.Re return nil, errors.New("no store to replace peer") } newPeer := &metapb.Peer{StoreId: store.GetID(), IsLearner: rf.Rule.Role == placement.Learner} - 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 41d99006982..3ecfb1097ad 100644 --- a/server/schedule/checker/rule_checker_test.go +++ b/server/schedule/checker/rule_checker_test.go @@ -71,6 +71,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)) } @@ -88,6 +89,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) @@ -95,6 +97,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) }