Skip to content

Commit

Permalink
schedule: correctly calculate the remove cost of the down peer (#4213)
Browse files Browse the repository at this point in the history
Signed-off-by: HunDunDM <hundundm@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
HunDunDM and ti-chi-bot authored Oct 15, 2021
1 parent 2230560 commit 4e41c8d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
15 changes: 13 additions & 2 deletions server/cluster/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,14 +1044,25 @@ func (s *testOperatorControllerSuite) TestDownStoreLimit(c *C) {
region := tc.GetRegion(1)
tc.setStoreDown(1)
tc.SetStoreLimit(1, storelimit.RemovePeer, 1)

region = region.Clone(core.WithDownPeers([]*pdpb.PeerStats{
{
Peer: region.GetStorePeer(1),
DownSeconds: 24 * 60 * 60,
},
}))
}), core.SetApproximateSize(1))
tc.putRegion(region)
for i := uint64(1); i < 20; i++ {
tc.addRegionStore(i+3, 100)
op := rc.Check(region)
c.Assert(op, NotNil)
c.Assert(oc.AddOperator(op), IsTrue)
oc.RemoveOperator(op)
}

for i := uint64(1); i <= 5; i++ {
region = region.Clone(core.SetApproximateSize(100))
tc.putRegion(region)
for i := uint64(20); i < 25; i++ {
tc.addRegionStore(i+3, 100)
op := rc.Check(region)
c.Assert(op, NotNil)
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/operator/influence.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *StoreInfluence) addStepCost(limitType storelimit.Type, cost int64) {
func (s *StoreInfluence) AdjustStepCost(limitType storelimit.Type, regionSize int64) {
if regionSize > storelimit.SmallRegionThreshold {
s.addStepCost(limitType, storelimit.RegionInfluence[limitType])
} else if regionSize <= storelimit.SmallRegionThreshold && regionSize > core.EmptyRegionApproximateSize {
} else if regionSize > core.EmptyRegionApproximateSize {
s.addStepCost(limitType, storelimit.SmallRegionInfluence[limitType])
}
}
6 changes: 3 additions & 3 deletions server/schedule/operator/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ func (rp RemovePeer) Influence(opInfluence OpInfluence, region *core.RegionInfo)
regionSize := region.GetApproximateSize()
from.RegionSize -= regionSize
from.RegionCount--
if rp.IsDownStore {
from.AdjustStepCost(storelimit.RemovePeer, storelimit.SmallRegionThreshold)
return

if rp.IsDownStore && regionSize > storelimit.SmallRegionThreshold {
regionSize = storelimit.SmallRegionThreshold
}
from.AdjustStepCost(storelimit.RemovePeer, regionSize)
}
Expand Down

0 comments on commit 4e41c8d

Please sign in to comment.