Skip to content

Commit

Permalink
add restart interval
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Oct 15, 2020
1 parent c51a422 commit 17a4fb3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
37 changes: 37 additions & 0 deletions server/schedule/filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package filter

import (
"fmt"
"time"

"github.com/golang/protobuf/proto"
"github.com/pingcap/kvproto/pkg/metapb"
Expand Down Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 17a4fb3

Please sign in to comment.