Skip to content

Commit d0a84da

Browse files
committed
mmaprototype: rename ac.analyzeFunc to ac.initialize
This commit renames ac.analyzeFunc to ac.initialize and updates the signature so constraints are passed directly to initialize, rather than being populated by caller.
1 parent e2fe79c commit d0a84da

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ type analyzedConstraints struct {
692692
// satisfiedBy slices represent sets that are non-intersecting.
693693
//
694694
// satisfiedByReplica[kind][i] contains the set of storeIDs that satisfy
695-
// constraints[i]. Populated by analyzeFunc and used later by mmma to
695+
// constraints[i]. Populated by initialize and used later by mmma to
696696
// determine candidates to satisfy constraints such as
697697
// candidatesToReplaceVoterForRebalance.
698698
// For example, satisfiedByReplica[voterIndex][0] = [1, 2, 3], means that
@@ -850,11 +850,11 @@ func (ac *analyzedConstraints) isConstraintSatisfied(constraintIndex int) bool {
850850
len(ac.satisfiedByReplica[nonVoterIndex][constraintIndex]) >= int(ac.constraints[constraintIndex].numReplicas)
851851
}
852852

853-
// analyzeFunc analyzes the current replica set and determines which constraints
854-
// replicas satisfy, populating ac.satisfiedByReplica and
855-
// ac.satisfiedNoConstraintReplica (both empty at the beginning). They are later
856-
// used by mma to compute lease-transfer and rebalancing candidates by functions
857-
// like candidatesToReplaceVoterForRebalance. The given buf.replicas is already
853+
// initialize analyzes the current replica set and determines which constraints
854+
// replicas satisfy, populating ac.constraints, ac.satisfiedByReplica and
855+
// ac.satisfiedNoConstraintReplica. They are later used by mma to compute
856+
// lease-transfer and rebalancing candidates by functions like
857+
// candidatesToReplaceVoterForRebalance. The given buf.replicas is already
858858
// populated with the current replica set from buf.tryAddingStore.
859859
//
860860
// For stores that satisfy no constraint,
@@ -912,9 +912,12 @@ func (ac *analyzedConstraints) isConstraintSatisfied(constraintIndex int) bool {
912912
// TODO(wenyihu6): document the lifecycle of scratch space
913913
// replicaConstraintIndices once understood. TODO(wenyihu6): add more tests +
914914
// examples here
915-
func (ac *analyzedConstraints) analyzeFunc(
916-
buf *analyzeConstraintsBuf, constraintMatcher storeMatchesConstraintInterface,
915+
func (ac *analyzedConstraints) initialize(
916+
constraints []internedConstraintsConjunction,
917+
buf *analyzeConstraintsBuf,
918+
constraintMatcher storeMatchesConstraintInterface,
917919
) {
920+
ac.constraints = constraints
918921
if len(ac.constraints) == 0 {
919922
// Nothing to do.
920923
return
@@ -1081,12 +1084,10 @@ func (rac *rangeAnalyzedConstraints) finishInit(
10811084
rac.replicas = rac.buf.replicas
10821085

10831086
if spanConfig.constraints != nil {
1084-
rac.constraints.constraints = spanConfig.constraints
1085-
rac.constraints.analyzeFunc(&rac.buf, constraintMatcher)
1087+
rac.constraints.initialize(spanConfig.constraints, &rac.buf, constraintMatcher)
10861088
}
10871089
if spanConfig.voterConstraints != nil {
1088-
rac.voterConstraints.constraints = spanConfig.voterConstraints
1089-
rac.voterConstraints.analyzeFunc(&rac.buf, constraintMatcher)
1090+
rac.voterConstraints.initialize(spanConfig.voterConstraints, &rac.buf, constraintMatcher)
10901091
}
10911092

10921093
rac.leaseholderID = leaseholder

0 commit comments

Comments
 (0)