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

scatter: fix incorrect judgment condition (#7111) #7119

Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions pkg/schedule/region_scatterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,14 @@ func (r *RegionScatterer) selectCandidates(region *core.RegionInfo, oldFit *plac
}
}
for _, store := range stores {
<<<<<<< HEAD:pkg/schedule/region_scatterer.go
storeCount := context.selectedPeer.TotalCountByStore(store.GetID())
=======
storeCount := context.selectedPeer.Get(store.GetID(), group)
if store.GetID() == peer.GetStoreId() {
originStorePickedCount = storeCount
}
>>>>>>> 24fffdf71 (scatter: fix incorrect judgment condition (#7111)):pkg/schedule/scatter/region_scatterer.go
// If storeCount is equal to the maxStoreTotalCount, we should skip this store as candidate.
// If the storeCount are all the same for the whole cluster(maxStoreTotalCount == minStoreTotalCount), any store
// could be selected as candidate.
Expand Down
29 changes: 25 additions & 4 deletions pkg/schedule/region_scatterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestScatterRegions(t *testing.T) {
scatter(re, 5, 50, true)
scatter(re, 5, 500, true)
scatter(re, 6, 50, true)
scatter(re, 7, 71, true)
scatter(re, 5, 50, false)
scatterSpecial(re, 3, 6, 50)
scatterSpecial(re, 5, 5, 50)
Expand Down Expand Up @@ -126,20 +127,40 @@ func scatter(re *require.Assertions, numStores, numRegions uint64, useRules bool
}
}
}
maxStorePeerTotalCount := uint64(0)
minStorePeerTotalCount := uint64(math.MaxUint64)

// Each store should have the same number of peers.
for _, count := range countPeers {
re.LessOrEqual(float64(count), 1.1*float64(numRegions*3)/float64(numStores))
re.GreaterOrEqual(float64(count), 0.9*float64(numRegions*3)/float64(numStores))
if count > maxStorePeerTotalCount {
maxStorePeerTotalCount = count
}
if count < minStorePeerTotalCount {
minStorePeerTotalCount = count
}
}
re.LessOrEqual(maxStorePeerTotalCount-minStorePeerTotalCount, uint64(1))

// Each store should have the same number of leaders.
re.Len(countPeers, int(numStores))
re.Len(countLeader, int(numStores))

maxStoreLeaderTotalCount := uint64(0)
minStoreLeaderTotalCount := uint64(math.MaxUint64)
for _, count := range countLeader {
re.LessOrEqual(float64(count), 1.1*float64(numRegions)/float64(numStores))
re.GreaterOrEqual(float64(count), 0.9*float64(numRegions)/float64(numStores))
if count > maxStoreLeaderTotalCount {
maxStoreLeaderTotalCount = count
}
if count < minStoreLeaderTotalCount {
minStoreLeaderTotalCount = count
}
}
<<<<<<< HEAD:pkg/schedule/region_scatterer_test.go
=======
// Since the scatter leader depends on the scatter result of the peer, the maximum difference is 2.
re.LessOrEqual(maxStoreLeaderTotalCount-minStoreLeaderTotalCount, uint64(2))
re.GreaterOrEqual(noNeedMoveNum, 0)
>>>>>>> 24fffdf71 (scatter: fix incorrect judgment condition (#7111)):pkg/schedule/scatter/region_scatterer_test.go
}

func scatterSpecial(re *require.Assertions, numOrdinaryStores, numSpecialStores, numRegions uint64) {
Expand Down