Skip to content

Commit

Permalink
schedule: not limit remove peer of the down store (#4097) (#4115)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: Ryan Leung <[email protected]>
  • Loading branch information
ti-chi-bot and rleungx authored Sep 15, 2021
1 parent 48b3ffd commit b6d8d5a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
30 changes: 30 additions & 0 deletions server/cluster/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,36 @@ func (s *testOperatorControllerSuite) TestStoreOverloadedWithReplace(c *C) {
c.Assert(lb.Schedule(tc), NotNil)
}

func (s *testOperatorControllerSuite) TestDownStoreLimit(c *C) {
tc, co, cleanup := prepare(nil, nil, nil, c)
defer cleanup()
oc := co.opController
rc := co.checkers.GetRuleChecker()

tc.addRegionStore(1, 100)
tc.addRegionStore(2, 100)
tc.addRegionStore(3, 100)
tc.addLeaderRegion(1, 1, 2, 3)

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,
},
}))

for i := uint64(1); i <= 5; i++ {
tc.addRegionStore(i+3, 100)
op := rc.Check(region)
c.Assert(op, NotNil)
c.Assert(oc.AddOperator(op), IsTrue)
oc.RemoveOperator(op)
}
}

var _ = Suite(&testScheduleControllerSuite{})

type testScheduleControllerSuite struct {
Expand Down
5 changes: 5 additions & 0 deletions server/schedule/checker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (c *CheckerController) GetMergeChecker() *checker.MergeChecker {
return c.mergeChecker
}

// GetRuleChecker returns the rule checker.
func (c *CheckerController) GetRuleChecker() *checker.RuleChecker {
return c.ruleChecker
}

// GetWaitingRegions returns the regions in the waiting list.
func (c *CheckerController) GetWaitingRegions() []*cache.Item {
return c.regionWaitingList.Elems()
Expand Down
12 changes: 9 additions & 3 deletions server/schedule/operator/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,15 @@ func (b *Builder) execAddPeer(peer *metapb.Peer) {
}

func (b *Builder) execRemovePeer(peer *metapb.Peer) {
b.steps = append(b.steps, RemovePeer{FromStore: peer.GetStoreId(), PeerID: peer.GetId()})
delete(b.currentPeers, peer.GetStoreId())
delete(b.toRemove, peer.GetStoreId())
removeStoreID := peer.GetStoreId()
var isDownStore bool
store := b.cluster.GetStore(removeStoreID)
if store != nil {
isDownStore = store.DownTime() > b.cluster.GetOpts().GetMaxStoreDownTime()
}
b.steps = append(b.steps, RemovePeer{FromStore: removeStoreID, PeerID: peer.GetId(), IsDownStore: isDownStore})
delete(b.currentPeers, removeStoreID)
delete(b.toRemove, removeStoreID)
}

func (b *Builder) execChangePeerV2(needEnter bool, needTransferLeader bool) {
Expand Down
5 changes: 5 additions & 0 deletions server/schedule/operator/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func (pl PromoteLearner) Influence(opInfluence OpInfluence, region *core.RegionI
// RemovePeer is an OpStep that removes a region peer.
type RemovePeer struct {
FromStore, PeerID uint64
IsDownStore bool
}

// ConfVerChanged returns the delta value for version increased by this step.
Expand Down Expand Up @@ -259,6 +260,10 @@ 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
}
from.AdjustStepCost(storelimit.RemovePeer, regionSize)
}

Expand Down

0 comments on commit b6d8d5a

Please sign in to comment.