Skip to content

Commit

Permalink
placement: change ValidateStores condition (tikv#4700)
Browse files Browse the repository at this point in the history
close tikv#4690

change ValidateStores condition

Signed-off-by: Cabinfever_B <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
CabinfeverB and ti-chi-bot authored Mar 4, 2022
1 parent 6b0cafb commit bf2d784
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/schedule/placement/region_rule_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}

Expand Down
16 changes: 16 additions & 0 deletions server/schedule/placement/region_rule_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package placement

import (
"time"

. "github.com/pingcap/check"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
Expand Down Expand Up @@ -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
Expand All @@ -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)}))
Expand Down

0 comments on commit bf2d784

Please sign in to comment.