Skip to content

Commit 293df0c

Browse files
committed
mmaprototype: fix out of bounds check on index bump
1 parent 149a4b2 commit 293df0c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func doStructuralNormalization(conf *normalizedSpanConfig) error {
467467
// don't know the semantics of regions, zones or the universe of possible
468468
// values of the zone.
469469
index := 0
470-
for rels[index].voterAndAllRel == conjPossiblyIntersecting {
470+
for index < len(rels) && rels[index].voterAndAllRel == conjPossiblyIntersecting {
471471
index++
472472
}
473473
var err error
@@ -691,7 +691,7 @@ func doStructuralNormalization(conf *normalizedSpanConfig) error {
691691
})
692692
// Ignore conjPossiblyIntersecting.
693693
index = 0
694-
for rels[index].voterAndAllRel == conjPossiblyIntersecting {
694+
for index < len(rels) && rels[index].voterAndAllRel == conjPossiblyIntersecting {
695695
index++
696696
}
697697
voterConstraintHasEqualityWithConstraint := make([]bool, len(conf.voterConstraints))

pkg/kv/kvserver/allocator/mmaprototype/testdata/normalize_config

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,3 +634,25 @@ output:
634634
+region=a,+zone=a1:1
635635
+region=a,+zone=a2:1
636636
:1
637+
638+
# Regression test for out-of-bounds access bug when all relationships are
639+
# conjPossiblyIntersecting. The voter constraint (+region=a,+zone=a1) and the
640+
# all-replica constraint (+region=a,+zone=a2) share +region=a but differ in
641+
# zone constraints, creating the only possibly intersecting relationship.
642+
normalize num-replicas=3 num-voters=3
643+
constraint num-replicas=3 +region=a +zone=a2
644+
voter-constraint num-replicas=3 +region=a +zone=a1
645+
----
646+
input:
647+
num-replicas=3 num-voters=3
648+
constraints:
649+
+region=a,+zone=a2:3
650+
voter-constraints:
651+
+region=a,+zone=a1:3
652+
err=could not satisfy all voter constraints due to non-intersecting conjunctions in voter and all replica constraints
653+
output:
654+
num-replicas=3 num-voters=3
655+
constraints:
656+
+region=a,+zone=a2:3
657+
voter-constraints:
658+
+region=a,+zone=a1:3

0 commit comments

Comments
 (0)