Skip to content

Commit 3ec86c8

Browse files
committed
mmaprototype: move isConstraintSatisfied to a closure
This commit moves isConstraintSatisfied from a struct method to a helper closure inside ac.initialize.
1 parent d0a84da commit 3ec86c8

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -842,14 +842,6 @@ type storeMatchesConstraintInterface interface {
842842
storeMatches(storeID roachpb.StoreID, constraintConj constraintsConj) bool
843843
}
844844

845-
// isConstraintSatisfied checks if the given constraint index has been fully
846-
// satisfied by the stores currently assigned to it.
847-
// TODO(wenyihu6): voter constraint should only count voters here (#158109)
848-
func (ac *analyzedConstraints) isConstraintSatisfied(constraintIndex int) bool {
849-
return len(ac.satisfiedByReplica[voterIndex][constraintIndex])+
850-
len(ac.satisfiedByReplica[nonVoterIndex][constraintIndex]) >= int(ac.constraints[constraintIndex].numReplicas)
851-
}
852-
853845
// initialize analyzes the current replica set and determines which constraints
854846
// replicas satisfy, populating ac.constraints, ac.satisfiedByReplica and
855847
// ac.satisfiedNoConstraintReplica. They are later used by mma to compute
@@ -951,12 +943,21 @@ func (ac *analyzedConstraints) initialize(
951943
// Else, satisfied multiple constraints. Don't choose yet.
952944
}
953945
}
946+
947+
// isConstraintSatisfied checks if the given constraint index has been fully
948+
// satisfied by the stores currently assigned to it.
949+
// TODO(wenyihu6): voter constraint should only count voters here (#158109)
950+
isConstraintSatisfied := func(constraintIndex int) bool {
951+
return len(ac.satisfiedByReplica[voterIndex][constraintIndex])+
952+
len(ac.satisfiedByReplica[nonVoterIndex][constraintIndex]) >= int(ac.constraints[constraintIndex].numReplicas)
953+
}
954+
954955
// The only stores not yet in ac are the ones that satisfy multiple
955956
// constraints. For each store, the constraint indices it satisfies are in
956957
// increasing order. Satisfy constraints in order, while not
957958
// oversatisfying.
958959
for j := range ac.constraints {
959-
satisfied := ac.isConstraintSatisfied(j)
960+
satisfied := isConstraintSatisfied(j)
960961
if satisfied {
961962
continue
962963
}
@@ -968,7 +969,7 @@ func (ac *analyzedConstraints) initialize(
968969
ac.satisfiedByReplica[kind][j] =
969970
append(ac.satisfiedByReplica[kind][j], buf.replicas[kind][i].StoreID)
970971
buf.replicaConstraintIndices[kind][i] = constraintIndices[:0]
971-
satisfied = ac.isConstraintSatisfied(j)
972+
satisfied = isConstraintSatisfied(j)
972973
// This store is finished.
973974
break
974975
}

0 commit comments

Comments
 (0)