From 17a4fb3459ac0393bf54026e84cc6d5c5fc5a4fe Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 15 Oct 2020 15:24:25 +0800 Subject: [PATCH] add restart interval Signed-off-by: lhy1024 --- server/schedule/filter/filters.go | 37 +++++++++++++++++++++++++++++++ server/schedulers/hot_region.go | 20 ++++++++++------- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/server/schedule/filter/filters.go b/server/schedule/filter/filters.go index 7ae154b3ee9..b74eda4f1d0 100644 --- a/server/schedule/filter/filters.go +++ b/server/schedule/filter/filters.go @@ -15,6 +15,7 @@ package filter import ( "fmt" + "time" "github.com/golang/protobuf/proto" "github.com/pingcap/kvproto/pkg/metapb" @@ -147,6 +148,42 @@ func (f *storageThresholdFilter) Target(opt *config.PersistOptions, store *core. return !store.IsLowSpace(opt.GetLowSpaceRatio()) } +type restartFilter struct { + scope string + interval time.Duration +} + +// NewRestartFilter creates a Filter that filters restart recently + +func NewRestartFilter(scope string, interval time.Duration) Filter { + return &restartFilter{ + scope: scope, + interval: interval, + } +} + +func (f *restartFilter) Scope() string { + return f.scope +} + +func (f *restartFilter) Type() string { + return "restart-filter" +} + +func (f *restartFilter) Source(opt *config.PersistOptions, store *core.StoreInfo) bool { + return f.isRecentlyRestart(store) +} + +func (f *restartFilter) Target(opt *config.PersistOptions, store *core.StoreInfo) bool { + return f.isRecentlyRestart(store) +} + +func (f *restartFilter) isRecentlyRestart(store *core.StoreInfo) bool { + timeStamp := store.GetStoreStats().StartTime + duration := time.Since(time.Unix(int64(timeStamp), 0)) + return duration > f.interval +} + // distinctScoreFilter ensures that distinct score will not decrease. type distinctScoreFilter struct { scope string diff --git a/server/schedulers/hot_region.go b/server/schedulers/hot_region.go index 6a1156264a0..85a0506d48f 100644 --- a/server/schedulers/hot_region.go +++ b/server/schedulers/hot_region.go @@ -109,19 +109,22 @@ type hotScheduler struct { pendingSums [resourceTypeLen]map[uint64]Influence // config of hot scheduler conf *hotRegionSchedulerConfig + // skip interval + restartInterval time.Duration } func newHotScheduler(opController *schedule.OperatorController, conf *hotRegionSchedulerConfig) *hotScheduler { base := NewBaseScheduler(opController) ret := &hotScheduler{ - name: HotRegionName, - BaseScheduler: base, - leaderLimit: 1, - peerLimit: 1, - types: []rwType{write, read}, - r: rand.New(rand.NewSource(time.Now().UnixNano())), - regionPendings: make(map[uint64][2]*operator.Operator), - conf: conf, + name: HotRegionName, + BaseScheduler: base, + leaderLimit: 1, + peerLimit: 1, + types: []rwType{write, read}, + r: rand.New(rand.NewSource(time.Now().UnixNano())), + regionPendings: make(map[uint64][2]*operator.Operator), + conf: conf, + restartInterval: time.Minute * 10, } for ty := resourceType(0); ty < resourceTypeLen; ty++ { ret.pendings[ty] = map[*pendingInfluence]struct{}{} @@ -801,6 +804,7 @@ func (bs *balanceSolver) filterDstStores() map[uint64]*storeLoadDetail { filter.NewExcludedFilter(bs.sche.GetName(), bs.cur.region.GetStoreIds(), bs.cur.region.GetStoreIds()), filter.NewSpecialUseFilter(bs.sche.GetName(), filter.SpecialUseHotRegion), filter.NewPlacementSafeguard(bs.sche.GetName(), bs.cluster, bs.cur.region, srcStore), + filter.NewRestartFilter(bs.sche.GetName(), bs.sche.restartInterval), } candidates = bs.cluster.GetStores()