Skip to content

Commit

Permalink
checker: fix the operator priority (#3694)
Browse files Browse the repository at this point in the history
* fix the operator priority

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

* add tests

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

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
rleungx and ti-chi-bot authored May 24, 2021
1 parent 866e856 commit 172a89c
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 @@ -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) {
Expand All @@ -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) {
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 @@ -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))
}

Expand Down Expand Up @@ -137,13 +138,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 172a89c

Please sign in to comment.