@@ -1159,7 +1159,7 @@ func rankedCandidateListForAllocation(
1159
1159
continue
1160
1160
}
1161
1161
1162
- diversityScore := diversityAllocateScore (s , existingStoreLocalities )
1162
+ diversityScore := diversityAllocateScore (s . Locality () , existingStoreLocalities )
1163
1163
balanceScore := options .balanceScore (validStoreList , s .Capacity )
1164
1164
var hasNonVoter bool
1165
1165
if targetType == VoterTarget {
@@ -1656,9 +1656,10 @@ func rankedCandidateListForRebalancing(
1656
1656
// this stage, in additon to hard checks and validation.
1657
1657
// TODO(kvoli,ayushshah15): Refactor this to make it harder to
1658
1658
// inadvertently break the invariant above,
1659
+ locality := store .Locality ()
1659
1660
constraintsOK , necessary , voterNecessary := rebalanceConstraintsChecker (store , existing .store )
1660
1661
diversityScore := diversityRebalanceFromScore (
1661
- store , existing .store .StoreID , existingStoreLocalities )
1662
+ locality , existing .store .StoreID , existingStoreLocalities )
1662
1663
cand := candidate {
1663
1664
store : store ,
1664
1665
valid : constraintsOK ,
@@ -1676,7 +1677,7 @@ func rankedCandidateListForRebalancing(
1676
1677
"s%d: should-rebalance(necessary/diversity=s%d): oldNecessary:%t, newNecessary:%t, " +
1677
1678
"oldDiversity:%f, newDiversity:%f, locality:%q" ,
1678
1679
existing .store .StoreID , store .StoreID , existing .necessary , cand .necessary ,
1679
- existing .diversityScore , cand .diversityScore , store . Locality () )
1680
+ existing .diversityScore , cand .diversityScore , locality )
1680
1681
}
1681
1682
}
1682
1683
}
@@ -2236,7 +2237,7 @@ func RangeDiversityScore(existingStoreLocalities map[roachpb.StoreID]roachpb.Loc
2236
2237
// desirable it would be to add a replica to store. A higher score means the
2237
2238
// store is a better fit.
2238
2239
func diversityAllocateScore (
2239
- store roachpb.StoreDescriptor , existingStoreLocalities map [roachpb.StoreID ]roachpb.Locality ,
2240
+ storeLocality roachpb.Locality , existingStoreLocalities map [roachpb.StoreID ]roachpb.Locality ,
2240
2241
) float64 {
2241
2242
var sumScore float64
2242
2243
var numSamples int
@@ -2245,7 +2246,7 @@ func diversityAllocateScore(
2245
2246
// consider adding the pairwise average diversity of the existing replicas
2246
2247
// is the same.
2247
2248
for _ , locality := range existingStoreLocalities {
2248
- newScore := store . Locality () .DiversityScore (locality )
2249
+ newScore := storeLocality .DiversityScore (locality )
2249
2250
sumScore += newScore
2250
2251
numSamples ++
2251
2252
}
@@ -2296,8 +2297,9 @@ func diversityRebalanceScore(
2296
2297
var maxScore float64
2297
2298
// For every existing node, calculate what the diversity score would be if we
2298
2299
// remove that node's replica to replace it with one on the provided store.
2300
+ storeLocality := store .Locality ()
2299
2301
for removedStoreID := range existingStoreLocalities {
2300
- score := diversityRebalanceFromScore (store , removedStoreID , existingStoreLocalities )
2302
+ score := diversityRebalanceFromScore (storeLocality , removedStoreID , existingStoreLocalities )
2301
2303
if score > maxScore {
2302
2304
maxScore = score
2303
2305
}
@@ -2312,7 +2314,7 @@ func diversityRebalanceScore(
2312
2314
// A higher score indicates that the provided store is a better fit for the
2313
2315
// range.
2314
2316
func diversityRebalanceFromScore (
2315
- store roachpb.StoreDescriptor ,
2317
+ storeLocality roachpb.Locality ,
2316
2318
fromStoreID roachpb.StoreID ,
2317
2319
existingStoreLocalities map [roachpb.StoreID ]roachpb.Locality ,
2318
2320
) float64 {
@@ -2324,7 +2326,7 @@ func diversityRebalanceFromScore(
2324
2326
if storeID == fromStoreID {
2325
2327
continue
2326
2328
}
2327
- newScore := store . Locality () .DiversityScore (locality )
2329
+ newScore := storeLocality .DiversityScore (locality )
2328
2330
sumScore += newScore
2329
2331
numSamples ++
2330
2332
for otherStoreID , otherLocality := range existingStoreLocalities {
0 commit comments