Skip to content

Commit d499de1

Browse files
ti-chi-botCabinfeverBti-chi-bot[bot]
authored
scatter: fix incorrect judgment condition (#7111) (#7118)
close #7109 Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io> Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com> Co-authored-by: Yongbo Jiang <cabinfeveroier@gmail.com> Co-authored-by: Cabinfever_B <cabinfeveroier@gmail.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent ed629e9 commit d499de1

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

server/schedule/region_scatterer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (r *RegionScatterer) selectNewPeer(context engineContext, group string, pee
437437
originStorePickedCount := uint64(math.MaxUint64)
438438
for _, store := range stores {
439439
storeCount := context.selectedPeer.Get(store.GetID(), group)
440-
if store.GetID() == peer.GetId() {
440+
if store.GetID() == peer.GetStoreId() {
441441
originStorePickedCount = storeCount
442442
}
443443
// If storeCount is equal to the maxStoreTotalCount, we should skip this store as candidate.

server/schedule/region_scatterer_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func TestScatterRegions(t *testing.T) {
6666
scatter(re, 5, 50, true)
6767
scatter(re, 5, 500, true)
6868
scatter(re, 6, 50, true)
69+
scatter(re, 7, 71, true)
6970
scatter(re, 5, 50, false)
7071
scatterSpecial(re, 3, 6, 50)
7172
scatterSpecial(re, 5, 5, 50)
@@ -125,19 +126,33 @@ func scatter(re *require.Assertions, numStores, numRegions uint64, useRules bool
125126
}
126127
}
127128
}
129+
maxStorePeerTotalCount := uint64(0)
130+
minStorePeerTotalCount := uint64(math.MaxUint64)
128131

129132
// Each store should have the same number of peers.
130133
for _, count := range countPeers {
131-
re.LessOrEqual(float64(count), 1.1*float64(numRegions*3)/float64(numStores))
132-
re.GreaterOrEqual(float64(count), 0.9*float64(numRegions*3)/float64(numStores))
134+
if count > maxStorePeerTotalCount {
135+
maxStorePeerTotalCount = count
136+
}
137+
if count < minStorePeerTotalCount {
138+
minStorePeerTotalCount = count
139+
}
133140
}
141+
re.LessOrEqual(maxStorePeerTotalCount-minStorePeerTotalCount, uint64(1))
134142

135143
// Each store should have the same number of leaders.
136144
re.Len(countPeers, int(numStores))
137145
re.Len(countLeader, int(numStores))
146+
147+
maxStoreLeaderTotalCount := uint64(0)
148+
minStoreLeaderTotalCount := uint64(math.MaxUint64)
138149
for _, count := range countLeader {
139-
re.LessOrEqual(float64(count), 1.1*float64(numRegions)/float64(numStores))
140-
re.GreaterOrEqual(float64(count), 0.9*float64(numRegions)/float64(numStores))
150+
if count > maxStoreLeaderTotalCount {
151+
maxStoreLeaderTotalCount = count
152+
}
153+
if count < minStoreLeaderTotalCount {
154+
minStoreLeaderTotalCount = count
155+
}
141156
}
142157
}
143158

0 commit comments

Comments
 (0)