diff --git a/server/schedule/placement/region_rule_cache.go b/server/schedule/placement/region_rule_cache.go index a83968bc592..7026533d295 100644 --- a/server/schedule/placement/region_rule_cache.go +++ b/server/schedule/placement/region_rule_cache.go @@ -230,7 +230,7 @@ func toRegionCache(r *core.RegionInfo) regionCache { // Only Up store should be cached in RegionFitCache func ValidateStores(stores []*core.StoreInfo) bool { return slice.NoneOf(stores, func(i int) bool { - return stores[i].IsRemoving() && stores[i].IsDisconnected() + return stores[i].IsRemoving() || stores[i].IsDisconnected() }) } diff --git a/server/schedule/placement/region_rule_cache_test.go b/server/schedule/placement/region_rule_cache_test.go index d19c41e5b50..54f32ad26ac 100644 --- a/server/schedule/placement/region_rule_cache_test.go +++ b/server/schedule/placement/region_rule_cache_test.go @@ -15,6 +15,8 @@ package placement import ( + "time" + . "github.com/pingcap/check" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" @@ -175,6 +177,10 @@ func (s *testRuleSuite) TestRegionRuleFitCache(c *C) { c.Log(testcase.name) c.Assert(cache.IsUnchanged(testcase.region, testcase.rules, mockStores(3)), Equals, testcase.unchanged) } + for _, testcase := range testcases { + c.Log(testcase.name) + c.Assert(cache.IsUnchanged(testcase.region, testcase.rules, mockStoresNoHeartbeat(3)), Equals, false) + } // Invalid Input4 c.Assert(cache.IsUnchanged(mockRegion(3, 0), addExtraRules(0), nil), IsFalse) // Invalid Input5 @@ -197,6 +203,16 @@ func mockRegionRuleFitCache(region *core.RegionInfo, rules []*Rule, regionStores } func mockStores(num int) []*core.StoreInfo { + stores := make([]*core.StoreInfo, 0, num) + now := time.Now() + for i := 1; i <= num; i++ { + stores = append(stores, core.NewStoreInfo(&metapb.Store{Id: uint64(i)}, + core.SetLastHeartbeatTS(now))) + } + return stores +} + +func mockStoresNoHeartbeat(num int) []*core.StoreInfo { stores := make([]*core.StoreInfo, 0, num) for i := 1; i <= num; i++ { stores = append(stores, core.NewStoreInfo(&metapb.Store{Id: uint64(i)}))