Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: priority to fix orphan peers (#3522) #3529

Merged
merged 5 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions server/schedule/checker/rule_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (c *RuleChecker) Check(region *core.RegionInfo) *operator.Operator {
// multiple rules.
return c.fixRange(region)
}
op, err := c.fixOrphanPeers(region, fit)
if err == nil && op != nil {
return op
}
log.Debug("fail to fix orphan peer", errs.ZapError(err))
for _, rf := range fit.RuleFits {
op, err := c.fixRulePeer(region, fit, rf)
if err != nil {
Expand All @@ -71,12 +76,7 @@ func (c *RuleChecker) Check(region *core.RegionInfo) *operator.Operator {
return op
}
}
op, err := c.fixOrphanPeers(region, fit)
if err != nil {
log.Debug("fail to fix orphan peer", errs.ZapError(err))
return nil
}
return op
return nil
}

func (c *RuleChecker) fixRange(region *core.RegionInfo) *operator.Operator {
Expand Down
164 changes: 164 additions & 0 deletions server/schedule/checker/rule_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,167 @@ func (s *testRuleCheckerSuite) TestIssue2419(c *C) {
c.Assert(op.Step(1).(operator.PromoteLearner).ToStore, Equals, uint64(4))
c.Assert(op.Step(2).(operator.RemovePeer).FromStore, Equals, uint64(3))
}
<<<<<<< HEAD
=======

// Ref https://github.com/tikv/pd/issues/3521
// The problem is when offline a store, we may add learner multiple times if
// the operator is timeout.
func (s *testRuleCheckerSuite) TestIssue3521_PriorityFixOrphanPeer(c *C) {
s.cluster.AddLabelsStore(1, 1, map[string]string{"host": "host1"})
s.cluster.AddLabelsStore(2, 1, map[string]string{"host": "host1"})
s.cluster.AddLabelsStore(3, 1, map[string]string{"host": "host2"})
s.cluster.AddLabelsStore(4, 1, map[string]string{"host": "host4"})
s.cluster.AddLabelsStore(5, 1, map[string]string{"host": "host5"})
s.cluster.AddLeaderRegionWithRange(1, "", "", 1, 2, 3)
op := s.rc.Check(s.cluster.GetRegion(1))
c.Assert(op, IsNil)
var add operator.AddLearner
var remove operator.RemovePeer
s.cluster.SetStoreOffline(2)
op = s.rc.Check(s.cluster.GetRegion(1))
c.Assert(op, NotNil)
c.Assert(op.Step(0), FitsTypeOf, add)
c.Assert(op.Desc(), Equals, "replace-rule-offline-peer")
r := s.cluster.GetRegion(1).Clone(core.WithAddPeer(
&metapb.Peer{
Id: 5,
StoreId: 4,
Role: metapb.PeerRole_Learner,
}))
s.cluster.PutRegion(r)
op = s.rc.Check(s.cluster.GetRegion(1))
c.Assert(op.Step(0), FitsTypeOf, remove)
c.Assert(op.Desc(), Equals, "remove-orphan-peer")
}

func (s *testRuleCheckerSuite) TestIssue3293(c *C) {
s.cluster.AddLabelsStore(1, 1, map[string]string{"host": "host1"})
s.cluster.AddLabelsStore(2, 1, map[string]string{"host": "host1"})
s.cluster.AddLabelsStore(3, 1, map[string]string{"host": "host2"})
s.cluster.AddLabelsStore(4, 1, map[string]string{"host": "host4"})
s.cluster.AddLabelsStore(5, 1, map[string]string{"host": "host5"})
s.cluster.AddLeaderRegionWithRange(1, "", "", 1, 2)
err := s.ruleManager.SetRule(&placement.Rule{
GroupID: "TiDB_DDL_51",
ID: "0",
Role: placement.Follower,
Count: 1,
LabelConstraints: []placement.LabelConstraint{
{
Key: "host",
Values: []string{
"host5",
},
Op: placement.In,
},
},
})
c.Assert(err, IsNil)
s.cluster.DeleteStore(s.cluster.TakeStore(5))
err = s.ruleManager.SetRule(&placement.Rule{
GroupID: "TiDB_DDL_51",
ID: "default",
Role: placement.Voter,
Count: 3,
})
c.Assert(err, IsNil)
err = s.ruleManager.DeleteRule("pd", "default")
c.Assert(err, IsNil)
op := s.rc.Check(s.cluster.GetRegion(1))
c.Assert(op, NotNil)
c.Assert(op.Desc(), Equals, "add-rule-peer")
}

func (s *testRuleCheckerSuite) TestIssue3299(c *C) {
s.cluster.AddLabelsStore(1, 1, map[string]string{"host": "host1"})
s.cluster.AddLabelsStore(2, 1, map[string]string{"dc": "sh"})
s.cluster.AddLeaderRegionWithRange(1, "", "", 1, 2)

testCases := []struct {
constraints []placement.LabelConstraint
err string
}{
{
constraints: []placement.LabelConstraint{
{
Key: "host",
Values: []string{"host5"},
Op: placement.In,
},
},
err: ".*can not match any store",
},
{
constraints: []placement.LabelConstraint{
{
Key: "ho",
Values: []string{"sh"},
Op: placement.In,
},
},
err: ".*can not match any store",
},
{
constraints: []placement.LabelConstraint{
{
Key: "host",
Values: []string{"host1"},
Op: placement.In,
},
{
Key: "host",
Values: []string{"host1"},
Op: placement.NotIn,
},
},
err: ".*can not match any store",
},
{
constraints: []placement.LabelConstraint{
{
Key: "host",
Values: []string{"host1"},
Op: placement.In,
},
{
Key: "host",
Values: []string{"host3"},
Op: placement.In,
},
},
err: ".*can not match any store",
},
{
constraints: []placement.LabelConstraint{
{
Key: "host",
Values: []string{"host1"},
Op: placement.In,
},
{
Key: "host",
Values: []string{"host1"},
Op: placement.In,
},
},
err: "",
},
}

for _, t := range testCases {
err := s.ruleManager.SetRule(&placement.Rule{
GroupID: "p",
ID: "0",
Role: placement.Follower,
Count: 1,
LabelConstraints: t.constraints,
})
if t.err != "" {
c.Assert(err, ErrorMatches, t.err)
} else {
c.Assert(err, IsNil)
}
}
}
>>>>>>> 60508bde... checker: priority to fix orphan peers (#3522)