Skip to content

Commit 24fffdf

Browse files
scatter: fix incorrect judgment condition (#7111)
close #7109 Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent b61a318 commit 24fffdf

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

pkg/schedule/scatter/region_scatterer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func (r *RegionScatterer) selectNewPeer(context engineContext, group string, pee
451451
originStorePickedCount := uint64(math.MaxUint64)
452452
for _, store := range stores {
453453
storeCount := context.selectedPeer.Get(store.GetID(), group)
454-
if store.GetID() == peer.GetId() {
454+
if store.GetID() == peer.GetStoreId() {
455455
originStorePickedCount = storeCount
456456
}
457457
// If storeCount is equal to the maxStoreTotalCount, we should skip this store as candidate.

pkg/schedule/scatter/region_scatterer_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func TestScatterRegions(t *testing.T) {
6767
scatter(re, 5, 50, true)
6868
scatter(re, 5, 500, true)
6969
scatter(re, 6, 50, true)
70+
scatter(re, 7, 71, true)
7071
scatter(re, 5, 50, false)
7172
scatterSpecial(re, 3, 6, 50)
7273
scatterSpecial(re, 5, 5, 50)
@@ -132,20 +133,36 @@ func scatter(re *require.Assertions, numStores, numRegions uint64, useRules bool
132133
}
133134
}
134135
}
136+
maxStorePeerTotalCount := uint64(0)
137+
minStorePeerTotalCount := uint64(math.MaxUint64)
135138

136139
// Each store should have the same number of peers.
137140
for _, count := range countPeers {
138-
re.LessOrEqual(float64(count), 1.1*float64(numRegions*3)/float64(numStores))
139-
re.GreaterOrEqual(float64(count), 0.9*float64(numRegions*3)/float64(numStores))
141+
if count > maxStorePeerTotalCount {
142+
maxStorePeerTotalCount = count
143+
}
144+
if count < minStorePeerTotalCount {
145+
minStorePeerTotalCount = count
146+
}
140147
}
148+
re.LessOrEqual(maxStorePeerTotalCount-minStorePeerTotalCount, uint64(1))
141149

142150
// Each store should have the same number of leaders.
143151
re.Len(countPeers, int(numStores))
144152
re.Len(countLeader, int(numStores))
153+
154+
maxStoreLeaderTotalCount := uint64(0)
155+
minStoreLeaderTotalCount := uint64(math.MaxUint64)
145156
for _, count := range countLeader {
146-
re.LessOrEqual(float64(count), 1.1*float64(numRegions)/float64(numStores))
147-
re.GreaterOrEqual(float64(count), 0.9*float64(numRegions)/float64(numStores))
157+
if count > maxStoreLeaderTotalCount {
158+
maxStoreLeaderTotalCount = count
159+
}
160+
if count < minStoreLeaderTotalCount {
161+
minStoreLeaderTotalCount = count
162+
}
148163
}
164+
// Since the scatter leader depends on the scatter result of the peer, the maximum difference is 2.
165+
re.LessOrEqual(maxStoreLeaderTotalCount-minStoreLeaderTotalCount, uint64(2))
149166
re.GreaterOrEqual(noNeedMoveNum, 0)
150167
}
151168

0 commit comments

Comments
 (0)