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

schedule: not limit remove peer of the down store (#4097) #4113

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions server/cluster/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,47 @@ 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.GetReplicaChecker()

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

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)
c.Assert(oc.AddOperator(op), IsTrue)
oc.RemoveOperator(op)
}
}

var _ = Suite(&testScheduleControllerSuite{})

type testScheduleControllerSuite struct {
Expand Down
1 change: 0 additions & 1 deletion server/schedule/checker/rule_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (c *RuleChecker) GetType() string {
// fix it.
func (c *RuleChecker) Check(region *core.RegionInfo) *operator.Operator {
checkerCounter.WithLabelValues("rule_checker", "check").Inc()

fit := c.cluster.FitRegion(region)
if len(fit.RuleFits) == 0 {
checkerCounter.WithLabelValues("rule_checker", "fix-range").Inc()
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 @@ -93,3 +93,8 @@ func (c *CheckerController) CheckRegion(region *core.RegionInfo) (bool, []*opera
func (c *CheckerController) GetMergeChecker() *checker.MergeChecker {
return c.mergeChecker
}

// GetReplicaChecker returns the replica checker.
func (c *CheckerController) GetReplicaChecker() *checker.ReplicaChecker {
return c.replicaChecker
}
8 changes: 7 additions & 1 deletion server/schedule/operator/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,13 @@ func (b *Builder) execAddPeer(p *metapb.Peer) {
}

func (b *Builder) execRemovePeer(p *metapb.Peer) {
b.steps = append(b.steps, RemovePeer{FromStore: p.GetStoreId()})
removeStoreID := p.GetStoreId()
var isDownStore bool
store := b.cluster.GetStore(removeStoreID)
if store != nil {
isDownStore = store.DownTime() > b.cluster.GetMaxStoreDownTime()
}
b.steps = append(b.steps, RemovePeer{FromStore: removeStoreID, IsDownStore: isDownStore})
b.currentPeers.Delete(p.GetStoreId())
b.toRemove.Delete(p.GetStoreId())
}
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 @@ -80,7 +80,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])
}
}
7 changes: 6 additions & 1 deletion server/schedule/operator/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func (pl PromoteLearner) Influence(opInfluence OpInfluence, region *core.RegionI

// RemovePeer is an OpStep that removes a region peer.
type RemovePeer struct {
FromStore uint64
FromStore uint64
IsDownStore bool
}

// ConfVerChanged returns true if the conf version has been changed by this step
Expand Down Expand Up @@ -252,6 +253,10 @@ func (rp RemovePeer) Influence(opInfluence OpInfluence, region *core.RegionInfo)
regionSize := region.GetApproximateSize()
from.RegionSize -= regionSize
from.RegionCount--

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

Expand Down