@@ -292,6 +292,15 @@ type ScorerOptions interface {
292
292
// the store represented by `sc` classifies as underfull, aroundTheMean, or
293
293
// overfull relative to all the stores in `sl`.
294
294
balanceScore (sl storepool.StoreList , sc roachpb.StoreCapacity ) balanceStatus
295
+ // adjustRangeCountForScoring returns the adjusted range count for scoring.
296
+ // Scorer options (IOOverloadOnlyScorerOptions) that do not score based on
297
+ // range count convergence returns 0. Otherwise, the returned range count here
298
+ // should usually be the same as the range count passed in
299
+ // (RangeCountScorerOptions, LoadScorerOptions, ScatterScorerOptions). This
300
+ // will later be used to calculate the relative difference when comparing the
301
+ // range count of the candidate stores. Lower range count means a better
302
+ // candidate to move the replica to.
303
+ adjustRangeCountForScoring (rangeCount int ) int
295
304
// rebalanceFromConvergenceScore assigns a convergence score to the store
296
305
// referred to by `eqClass.existing` based on whether moving a replica away
297
306
// from this store would converge its stats towards the mean (relative to the
@@ -385,6 +394,13 @@ func (bo BaseScorerOptions) maybeJitterStoreStats(
385
394
return sl
386
395
}
387
396
397
+ // adjustRangeCountForScoring returns the provided range count since that is the
398
+ // default behavior. BaseScorerOptionsNoConvergence is the only scorer option
399
+ // that does not want to consider range count in its scoring, so it returns 0.
400
+ func (bo BaseScorerOptions ) adjustRangeCountForScoring (rangeCount int ) int {
401
+ return rangeCount
402
+ }
403
+
388
404
// RangeCountScorerOptions is used by the replicateQueue to tell the Allocator's
389
405
// rebalancing machinery to base its balance/convergence scores on range counts.
390
406
// This means that the resulting rebalancing decisions will further the goal of
@@ -1155,14 +1171,15 @@ func rankedCandidateListForAllocation(
1155
1171
}
1156
1172
hasNonVoter = StoreHasReplica (s .StoreID , nonVoterReplTargets )
1157
1173
}
1174
+ rangeCountScore := options .adjustRangeCountForScoring (int (s .Capacity .RangeCount ))
1158
1175
candidates = append (candidates , candidate {
1159
1176
store : s ,
1160
1177
necessary : necessary ,
1161
1178
valid : constraintsOK ,
1162
1179
diversityScore : diversityScore ,
1163
1180
balanceScore : balanceScore ,
1164
1181
hasNonVoter : hasNonVoter ,
1165
- rangeCount : int ( s . Capacity . RangeCount ) ,
1182
+ rangeCount : rangeCountScore ,
1166
1183
})
1167
1184
}
1168
1185
if options .deterministicForTesting () {
@@ -1270,7 +1287,7 @@ func candidateListForRemoval(
1270
1287
candidates [i ].balanceScore = options .balanceScore (
1271
1288
removalCandidateStoreList , candidates [i ].store .Capacity ,
1272
1289
)
1273
- candidates [i ].rangeCount = int (candidates [i ].store .Capacity .RangeCount )
1290
+ candidates [i ].rangeCount = options . adjustRangeCountForScoring ( int (candidates [i ].store .Capacity .RangeCount ) )
1274
1291
}
1275
1292
// Re-sort to account for the ordering changes resulting from the addition of
1276
1293
// convergesScore, balanceScore, etc.
@@ -1735,7 +1752,7 @@ func rankedCandidateListForRebalancing(
1735
1752
balanceScore := options .balanceScore (comparable .candidateSL , existing .store .Capacity )
1736
1753
existing .convergesScore = convergesScore
1737
1754
existing .balanceScore = balanceScore
1738
- existing .rangeCount = int (existing .store .Capacity .RangeCount )
1755
+ existing .rangeCount = options . adjustRangeCountForScoring ( int (existing .store .Capacity .RangeCount ) )
1739
1756
}
1740
1757
1741
1758
var candidates candidateList
@@ -1761,7 +1778,7 @@ func rankedCandidateListForRebalancing(
1761
1778
)
1762
1779
cand .balanceScore = options .balanceScore (comparable .candidateSL , s .Capacity )
1763
1780
cand .convergesScore = options .rebalanceToConvergesScore (comparable , s )
1764
- cand .rangeCount = int (s .Capacity .RangeCount )
1781
+ cand .rangeCount = options . adjustRangeCountForScoring ( int (s .Capacity .RangeCount ) )
1765
1782
candidates = append (candidates , cand )
1766
1783
}
1767
1784
0 commit comments