Skip to content

Commit 1572ff3

Browse files
craig[bot]wenyihu6
andcommitted
Merge #153525
153525: mmaprototype: make conf read only in makeNormalizedSpanConfig r=tbg a=wenyihu6 Previously, when fixing how makeNormalizedSpanConfig uses conf.NumVoters to determine the number of voters, we incorrectly changed conf.NumVoters directly to conf.NumReplicas when its value was 0. This commit corrects the behavior by ensuring that the input conf is not modified when falling back to NumReplicas. Epic: none Release note: none Co-authored-by: wenyihu6 <[email protected]>
2 parents ee166ea + 65c4b07 commit 1572ff3

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

pkg/kv/kvserver/allocator/mmaprototype/constraint.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,12 @@ type internedLeasePreference struct {
252252
func makeNormalizedSpanConfig(
253253
conf *roachpb.SpanConfig, interner *stringInterner,
254254
) (*normalizedSpanConfig, error) {
255-
if conf.NumVoters == 0 {
256-
conf.NumVoters = conf.NumReplicas
257-
}
255+
numVoters := conf.GetNumVoters()
258256
var normalizedConstraints, normalizedVoterConstraints []internedConstraintsConjunction
259257
var err error
260258
if conf.VoterConstraints != nil {
261259
normalizedVoterConstraints, err = normalizeConstraints(
262-
conf.VoterConstraints, conf.NumVoters, interner)
260+
conf.VoterConstraints, numVoters, interner)
263261
if err != nil {
264262
return nil, err
265263
}
@@ -269,7 +267,7 @@ func makeNormalizedSpanConfig(
269267
if err != nil {
270268
return nil, err
271269
}
272-
} else if (conf.NumReplicas-conf.NumVoters > 0) || len(normalizedVoterConstraints) == 0 {
270+
} else if (conf.NumReplicas-numVoters > 0) || len(normalizedVoterConstraints) == 0 {
273271
// - No constraints, but have some non-voters.
274272
// - No voter constraints either.
275273
// Need an empty constraints conjunction so that non-voters or voters have
@@ -287,7 +285,7 @@ func makeNormalizedSpanConfig(
287285
constraints: interner.internConstraintsConj(conf.LeasePreferences[i].Constraints)})
288286
}
289287
nConf := &normalizedSpanConfig{
290-
numVoters: conf.NumVoters,
288+
numVoters: numVoters,
291289
numReplicas: conf.NumReplicas,
292290
constraints: normalizedConstraints,
293291
voterConstraints: normalizedVoterConstraints,

pkg/kv/kvserver/allocator/mmaprototype/constraint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func parseSpanConfig(t *testing.T, d *datadriven.TestData) roachpb.SpanConfig {
9797
}
9898

9999
func printSpanConfig(b *strings.Builder, conf roachpb.SpanConfig) {
100-
fmt.Fprintf(b, " num-replicas=%d num-voters=%d\n", conf.NumReplicas, conf.NumVoters)
100+
fmt.Fprintf(b, " num-replicas=%d num-voters=%d\n", conf.NumReplicas, conf.GetNumVoters())
101101
if len(conf.Constraints) > 0 {
102102
fmt.Fprintf(b, " constraints:\n")
103103
for _, cc := range conf.Constraints {

0 commit comments

Comments
 (0)