Skip to content

Commit

Permalink
schedule: fix the down peer cannot be repaired (#7996) (#8195)
Browse files Browse the repository at this point in the history
close #7808

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

Co-authored-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
ti-chi-bot and rleungx committed Jun 4, 2024
1 parent 33d839b commit 52464f0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/schedule/checker/replica_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ func (s *ReplicaStrategy) SelectStoreToFix(coLocationStores []*core.StoreInfo, o
}
// trick to avoid creating a slice with `old` removed.
s.swapStoreToFirst(coLocationStores, old)
return s.SelectStoreToAdd(coLocationStores[1:])
// If the coLocationStores only has one store, no need to remove.
// Otherwise, the other stores will be filtered.
if len(coLocationStores) > 1 {
coLocationStores = coLocationStores[1:]
}
return s.SelectStoreToAdd(coLocationStores)
}

// SelectStoreToImprove returns a store to replace oldStore. The location
Expand Down
60 changes: 60 additions & 0 deletions server/schedule/checker/rule_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1919,3 +1919,63 @@ func (suite *ruleCheckerTestSuite) TestRemoveOrphanPeer() {
suite.NotNil(op)
suite.Equal("remove-orphan-peer", op.Desc())
}

func (suite *ruleCheckerTestSuite) TestIssue7808() {
re := suite.Require()
suite.cluster.AddLabelsStore(1, 1, map[string]string{"host": "host1", "disk_type": "mix"})
suite.cluster.AddLabelsStore(2, 1, map[string]string{"host": "host2", "disk_type": "mix"})
suite.cluster.AddLabelsStore(3, 1, map[string]string{"host": "host3", "disk_type": "ssd"})
suite.cluster.AddLabelsStore(4, 1, map[string]string{"host": "host4", "disk_type": "ssd"})
suite.cluster.AddLabelsStore(5, 1, map[string]string{"host": "host5", "disk_type": "ssd"})
suite.cluster.AddLeaderRegionWithRange(1, "", "", 3, 4, 1)
err := suite.ruleManager.SetRules([]*placement.Rule{
{
GroupID: "pd",
ID: "1",
Role: placement.Voter,
Count: 2,
LabelConstraints: []placement.LabelConstraint{
{
Key: "disk_type",
Values: []string{
"ssd",
},
Op: placement.In,
},
},
LocationLabels: []string{"host"},
IsolationLevel: "host",
},
{
GroupID: "pd",
ID: "2",
Role: placement.Follower,
Count: 1,
LabelConstraints: []placement.LabelConstraint{
{
Key: "disk_type",
Values: []string{
"mix",
},
Op: placement.In,
},
},
LocationLabels: []string{"host"},
IsolationLevel: "host",
},
})
re.NoError(err)
err = suite.ruleManager.DeleteRule("pd", "default")
re.NoError(err)
suite.cluster.SetStoreDown(1)
region := suite.cluster.GetRegion(1)
downPeer := []*pdpb.PeerStats{
{Peer: region.GetStorePeer(1), DownSeconds: 6000},
}
region = region.Clone(core.WithDownPeers(downPeer))
suite.cluster.PutRegion(region)
op := suite.rc.Check(suite.cluster.GetRegion(1))
re.NotNil(op)
re.Equal("replace-rule-down-peer", op.Desc())
re.Contains(op.String(), "mv peer: store [1] to [2]")
}

0 comments on commit 52464f0

Please sign in to comment.