Skip to content

Commit

Permalink
fix test
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 17a4fb3 commit 5561bf1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 12 additions & 0 deletions pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func (mc *Cluster) AddLeaderStore(storeID uint64, leaderCount int, leaderSizes .
stats := &pdpb.StoreStats{}
stats.Capacity = 1000 * (1 << 20)
stats.Available = stats.Capacity - uint64(leaderCount)*10
stats.StartTime = uint32(time.Now().Add(-time.Minute * 30).Unix())
var leaderSize int64
if len(leaderSizes) != 0 {
leaderSize = leaderSizes[0]
Expand All @@ -228,6 +229,7 @@ func (mc *Cluster) AddRegionStore(storeID uint64, regionCount int) {
stats := &pdpb.StoreStats{}
stats.Capacity = 1000 * (1 << 20)
stats.Available = stats.Capacity - uint64(regionCount)*10
stats.StartTime = uint32(time.Now().Add(-time.Minute * 30).Unix())
store := core.NewStoreInfo(
&metapb.Store{Id: storeID, Labels: []*metapb.StoreLabel{
{
Expand Down Expand Up @@ -267,6 +269,7 @@ func (mc *Cluster) AddLabelsStore(storeID uint64, regionCount int, labels map[st
stats := &pdpb.StoreStats{}
stats.Capacity = 1000 * (1 << 20)
stats.Available = stats.Capacity - uint64(regionCount)*10
stats.StartTime = uint32(time.Now().Add(-time.Minute * 30).Unix())
store := core.NewStoreInfo(
&metapb.Store{
Id: storeID,
Expand Down Expand Up @@ -349,6 +352,15 @@ func (mc *Cluster) UpdateStoreLeaderWeight(storeID uint64, weight float64) {
mc.PutStore(newStore)
}

// UpdateStoreStartTime updates store start time.
func (mc *Cluster) UpdateStoreStartTime(storeID uint64, startTime uint32) {
store := mc.GetStore(storeID)
stats := store.GetStoreStats()
stats.StartTime = startTime
newStore := store.Clone(core.SetStoreStats(stats))
mc.PutStore(newStore)
}

// UpdateStoreRegionWeight updates store region weight.
func (mc *Cluster) UpdateStoreRegionWeight(storeID uint64, weight float64) {
store := mc.GetStore(storeID)
Expand Down
7 changes: 3 additions & 4 deletions server/schedule/filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ type restartFilter struct {
}

// NewRestartFilter creates a Filter that filters restart recently

func NewRestartFilter(scope string, interval time.Duration) Filter {
return &restartFilter{
scope: scope,
Expand All @@ -171,17 +170,17 @@ func (f *restartFilter) Type() string {
}

func (f *restartFilter) Source(opt *config.PersistOptions, store *core.StoreInfo) bool {
return f.isRecentlyRestart(store)
return !f.isRecentlyRestart(store)
}

func (f *restartFilter) Target(opt *config.PersistOptions, store *core.StoreInfo) bool {
return f.isRecentlyRestart(store)
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
return duration < f.interval
}

// distinctScoreFilter ensures that distinct score will not decrease.
Expand Down

0 comments on commit 5561bf1

Please sign in to comment.