Skip to content

Commit

Permalink
checker: fix the operator priority (#3694) (#3703)
Browse files Browse the repository at this point in the history
* This is an automated cherry-pick of #3694

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>

* resolve conflicts

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
ti-chi-bot and rleungx authored Jul 6, 2021
1 parent b6ac46c commit e649fe7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 12 additions & 2 deletions server/schedule/checker/rule_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions server/schedule/checker/rule_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -88,13 +89,15 @@ 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)
s.cluster.SetStoreOffline(2)
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)
}

Expand Down

0 comments on commit e649fe7

Please sign in to comment.