Skip to content

Commit 736723e

Browse files
craig[bot]wenyihu6
andcommitted
Merge #158006
158006: mmaprototype: panic for no leaseholders r=wenyihu6 a=wenyihu6 Epic: CRDB-55052 Release note: none --- **mmaprototype: panic for no leaseholders** This change commit ensureAnalyzedConstraints to panic when no leaseholder is found instead of returning a bool that errors. This state of no leaseholder should not occur — range messages are expected to include a leaseholder, and we validate that pending changes to the range state should not result in a range with no leaseholders. Co-authored-by: wenyihu6 <[email protected]>
2 parents 3b45e6a + fdf688f commit 736723e

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,9 @@ func sortTargetCandidateSetAndPick(
703703
return cands.candidates[j].StoreID
704704
}
705705

706-
func (cs *clusterState) ensureAnalyzedConstraints(rstate *rangeState) bool {
706+
func (cs *clusterState) ensureAnalyzedConstraints(rstate *rangeState) {
707707
if rstate.constraints != nil {
708-
return true
708+
return
709709
}
710710
// Populate the constraints.
711711
rac := newRangeAnalyzedConstraints()
@@ -721,13 +721,16 @@ func (cs *clusterState) ensureAnalyzedConstraints(rstate *rangeState) bool {
721721
if leaseholder < 0 {
722722
// Very dubious why the leaseholder (which must be a local store since there
723723
// are no pending changes) is not known.
724-
// TODO(sumeer): log an error.
725724
releaseRangeAnalyzedConstraints(rac)
726-
return false
725+
// Possible that we are observing stale state where we've transferred the
726+
// lease away but have not yet received a StoreLeaseholderMsg indicating
727+
// that there is a new leaseholder (and thus should drop this range).
728+
// However, even in this case, replica.IsLeaseholder should still be there
729+
// based on to the stale state, so this should still be impossible to hit.
730+
panic(errors.AssertionFailedf("no leaseholders found in %v", rstate.replicas))
727731
}
728732
rac.finishInit(rstate.conf, cs.constraintMatcher, leaseholder)
729733
rstate.constraints = rac
730-
return true
731734
}
732735

733736
// Consider the core logic for a change, rebalancing or recovery.

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ func (re *rebalanceEnv) rebalanceReplicas(
285285
log.KvDistribution.VInfof(ctx, 2, "skipping r%d: too soon after failed change", rangeID)
286286
continue
287287
}
288-
if !re.ensureAnalyzedConstraints(rstate) {
289-
log.KvDistribution.VInfof(ctx, 2, "skipping r%d: constraints analysis failed", rangeID)
290-
continue
291-
}
288+
re.ensureAnalyzedConstraints(rstate)
292289
isVoter, isNonVoter := rstate.constraints.replicaRole(store.StoreID)
293290
if !isVoter && !isNonVoter {
294291
// Due to REQUIREMENT(change-computation), the top-k is up to date, so
@@ -486,10 +483,7 @@ func (re *rebalanceEnv) rebalanceLeases(
486483
log.KvDistribution.VInfof(ctx, 2, "skipping r%d: too soon after failed change", rangeID)
487484
continue
488485
}
489-
if !re.ensureAnalyzedConstraints(rstate) {
490-
log.KvDistribution.VInfof(ctx, 2, "skipping r%d: constraints analysis failed", rangeID)
491-
continue
492-
}
486+
re.ensureAnalyzedConstraints(rstate)
493487
if rstate.constraints.leaseholderID != store.StoreID {
494488
// We should not panic here since the leaseQueue may have shed the
495489
// lease and informed MMA, since the last time MMA computed the

0 commit comments

Comments
 (0)