From 5561bf11de228fd38d4c93fd2c4b52664fa74d3f Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 15 Oct 2020 16:23:58 +0800 Subject: [PATCH] fix test Signed-off-by: lhy1024 --- pkg/mock/mockcluster/mockcluster.go | 12 ++++++++++++ server/schedule/filter/filters.go | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index 937eeb3b333..62e51a7cc5c 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -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] @@ -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{ { @@ -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, @@ -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) diff --git a/server/schedule/filter/filters.go b/server/schedule/filter/filters.go index b74eda4f1d0..3e9fcfca47e 100644 --- a/server/schedule/filter/filters.go +++ b/server/schedule/filter/filters.go @@ -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, @@ -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.