Skip to content

Commit 9b5259c

Browse files
committed
mmaprototype: move unused helper functions to constraint_unused.go
Previously, constraint_matcher.go included a few helper functions intended for future production use but not currently in use. This commit moves those helpers into their own dedicated file to make constraint_matcher.go smaller.
1 parent 96abade commit 9b5259c

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,6 @@ func (cm *constraintMatcher) setStore(sal StoreAttributesAndLocality) {
9393
}
9494
}
9595

96-
// removeStore is called for a store that is removed from the cluster.
97-
func (cm *constraintMatcher) removeStore(storeID roachpb.StoreID) {
98-
mc := cm.stores[storeID]
99-
if mc == nil {
100-
return
101-
}
102-
cm.allStores.remove(storeID)
103-
delete(cm.stores, storeID)
104-
for c := range mc.matched {
105-
matchedSet := cm.constraints[c]
106-
if matchedSet == nil {
107-
panic(errors.AssertionFailedf(
108-
"inconsistent state: store %d not found", storeID))
109-
}
110-
found := matchedSet.remove(storeID)
111-
if !found {
112-
panic(errors.AssertionFailedf(
113-
"inconsistent state: store %d not found", storeID))
114-
}
115-
}
116-
}
117-
11896
// storeMatchesConstraint is an internal helper method.
11997
func (cm *constraintMatcher) storeMatchesConstraint(
12098
sal StoreAttributesAndLocality, c internedConstraint,
@@ -236,33 +214,6 @@ func (cm *constraintMatcher) constrainStoresForExpr(expr constraintsDisj, set *s
236214
}
237215
}
238216

239-
func (cm *constraintMatcher) checkConsistency() error {
240-
for storeID, mc := range cm.stores {
241-
for c := range mc.matched {
242-
pl, ok := cm.constraints[c]
243-
if !ok {
244-
return errors.AssertionFailedf("constraint not found")
245-
}
246-
if !pl.contains(storeID) {
247-
return errors.AssertionFailedf("constraint set does not include storeID %d", storeID)
248-
}
249-
}
250-
}
251-
for c, pl := range cm.constraints {
252-
for _, storeID := range pl.storeSet {
253-
store, ok := cm.stores[storeID]
254-
if !ok {
255-
return errors.AssertionFailedf("constraint set mentions unknown storeID %d", storeID)
256-
}
257-
_, ok = store.matched[c]
258-
if !ok {
259-
return errors.AssertionFailedf("stores and constraints map are out of sync")
260-
}
261-
}
262-
}
263-
return nil
264-
}
265-
266217
// Avoid unused lint errors.
267218

268219
var _ = (&constraintMatcher{}).setStore

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,52 @@ func (rac *rangeAnalyzedConstraints) candidatesNonVoterConstraintsUnsatisfied()
446446
}
447447
return toRemoveNonVoters, toAdd, nil
448448
}
449+
450+
// removeStore is called for a store that is removed from the cluster.
451+
func (cm *constraintMatcher) removeStore(storeID roachpb.StoreID) {
452+
mc := cm.stores[storeID]
453+
if mc == nil {
454+
return
455+
}
456+
cm.allStores.remove(storeID)
457+
delete(cm.stores, storeID)
458+
for c := range mc.matched {
459+
matchedSet := cm.constraints[c]
460+
if matchedSet == nil {
461+
panic(errors.AssertionFailedf(
462+
"inconsistent state: store %d not found", storeID))
463+
}
464+
found := matchedSet.remove(storeID)
465+
if !found {
466+
panic(errors.AssertionFailedf(
467+
"inconsistent state: store %d not found", storeID))
468+
}
469+
}
470+
}
471+
472+
func (cm *constraintMatcher) checkConsistency() error {
473+
for storeID, mc := range cm.stores {
474+
for c := range mc.matched {
475+
pl, ok := cm.constraints[c]
476+
if !ok {
477+
return errors.AssertionFailedf("constraint not found")
478+
}
479+
if !pl.contains(storeID) {
480+
return errors.AssertionFailedf("constraint set does not include storeID %d", storeID)
481+
}
482+
}
483+
}
484+
for c, pl := range cm.constraints {
485+
for _, storeID := range pl.storeSet {
486+
store, ok := cm.stores[storeID]
487+
if !ok {
488+
return errors.AssertionFailedf("constraint set mentions unknown storeID %d", storeID)
489+
}
490+
_, ok = store.matched[c]
491+
if !ok {
492+
return errors.AssertionFailedf("stores and constraints map are out of sync")
493+
}
494+
}
495+
}
496+
return nil
497+
}

0 commit comments

Comments
 (0)