Skip to content

Commit

Permalink
This is an automated cherry-pick of tikv#7111
Browse files Browse the repository at this point in the history
close tikv#7109

Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
CabinfeverB authored and ti-chi-bot committed Sep 20, 2023
1 parent e8f95ac commit a0e9d38
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/schedule/region_scatterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (r *RegionScatterer) selectNewPeer(context engineContext, group string, pee
originStorePickedCount := uint64(math.MaxUint64)
for _, store := range stores {
storeCount := context.selectedPeer.Get(store.GetID(), group)
if store.GetID() == peer.GetId() {
if store.GetID() == peer.GetStoreId() {
originStorePickedCount = storeCount
}
// If storeCount is equal to the maxStoreTotalCount, we should skip this store as candidate.
Expand Down
29 changes: 25 additions & 4 deletions server/schedule/region_scatterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 @@ -125,20 +126,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:server/schedule/region_scatterer_test.go

Check failure on line 157 in server/schedule/region_scatterer_test.go

View workflow job for this annotation

GitHub Actions / statics

expected statement, found '<<'

Check failure on line 157 in server/schedule/region_scatterer_test.go

View workflow job for this annotation

GitHub Actions / statics

expected statement, found '<<'
=======

Check failure on line 158 in server/schedule/region_scatterer_test.go

View workflow job for this annotation

GitHub Actions / statics

expected operand, found '=='

Check failure on line 158 in server/schedule/region_scatterer_test.go

View workflow job for this annotation

GitHub Actions / statics

expected operand, found '=='
// 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

Check failure on line 162 in server/schedule/region_scatterer_test.go

View workflow job for this annotation

GitHub Actions / statics

illegal character U+0023 '#'

Check failure on line 162 in server/schedule/region_scatterer_test.go

View workflow job for this annotation

GitHub Actions / statics

illegal character U+0023 '#'
}

Check failure on line 163 in server/schedule/region_scatterer_test.go

View workflow job for this annotation

GitHub Actions / statics

expected operand, found '}'

Check failure on line 163 in server/schedule/region_scatterer_test.go

View workflow job for this annotation

GitHub Actions / statics

expected operand, found '}'

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

0 comments on commit a0e9d38

Please sign in to comment.