Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

placement: change ValidateStores condition #4700

Merged
merged 4 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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