Skip to content

Commit 8c97d77

Browse files
craig[bot]tbg
andcommitted
Merge #157060
157060: mmaprototype: use LeaseDisposition instead of VoterIsLagging bool r=tbg a=tbg We'll want to exercise this all properly in tests (for now it is hooked up in production, but nowhere else). This will be done as part of testing work for #156776. Epic: CRDB-55052 Co-authored-by: Tobias Grieger <tobias.b.grieger@gmail.com>
2 parents 2237dd8 + 89410b2 commit 8c97d77

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ func (a *allocatorState) rebalanceStores(
486486
}
487487
var candsSet candidateSet
488488
for _, cand := range cands {
489-
if a.cs.stores[cand.storeID].adjusted.replicas[rangeID].VoterIsLagging {
489+
if disp := a.cs.stores[cand.storeID].adjusted.replicas[rangeID].LeaseDisposition; disp != LeaseDispositionOK {
490490
// Don't transfer lease to a store that is lagging.
491-
log.KvDistribution.Infof(ctx, "skipping store s%d for lease transfer: replica is lagging",
492-
cand.storeID)
491+
log.KvDistribution.Infof(ctx, "skipping store s%d for lease transfer: lease disposition %v",
492+
cand.storeID, disp)
493493
continue
494494
}
495495
candSls := a.cs.computeLoadSummary(ctx, cand.storeID, &means.storeLoad, &means.nodeLoad)

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,9 @@ func (rit ReplicaIDAndType) subsumesChange(prev, next ReplicaIDAndType) bool {
117117

118118
type ReplicaState struct {
119119
ReplicaIDAndType
120-
// VoterIsLagging can be set for a VOTER_FULL replica that has fallen
121-
// behind, i.e., it's matching log is less than the current committed log.
122-
// It is a hint to the allocator not to transfer the lease to this replica.
123-
VoterIsLagging bool
124-
// TODO(kvoli,sumeerbhola): Consider adding in rac2.SendQueue information to
125-
// prevent lease transfers to replicas which are not able to take the lease
126-
// due to a send queue. Do we even need this, given the VoterIsLagging
127-
// should be true whenever there is a send queue? I suppose if we are
128-
// force-flushing to a replica, it is possible for VoterIsLagging to be
129-
// false and the send queue to be non-empty. But we could incorporate the
130-
// send-queue state into VoterIsLagging -- having two bools doesn't seem
131-
// beneficial.
120+
// LeaseDisposition can be set for a VOTER_FULL replica and communicates the
121+
// availability of this replica for lease transfers.
122+
LeaseDisposition LeaseDisposition
132123
}
133124

134125
// ChangeID is a unique ID, in the context of this data-structure and when
@@ -820,7 +811,7 @@ func (s StoreIDAndReplicaState) String() string {
820811

821812
// SafeFormat implements the redact.SafeFormatter interface.
822813
func (s StoreIDAndReplicaState) SafeFormat(w redact.SafePrinter, _ rune) {
823-
w.Printf("s%v:%v voterIsLagging:%v", s.StoreID, s.ReplicaState.ReplicaIDAndType, s.ReplicaState.VoterIsLagging)
814+
w.Printf("s%v:%v lease disposition:%v", s.StoreID, s.ReplicaState.ReplicaIDAndType, s.ReplicaState.LeaseDisposition)
824815
}
825816

826817
// rangeState is periodically updated based on reporting by the leaseholder.

pkg/kv/kvserver/mma_replica_store.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,17 @@ func constructRangeMsgReplicas(
125125
// should pass scratch memory to avoid unnecessary allocation.
126126
replicas := make([]mmaprototype.StoreIDAndReplicaState, 0, len(desc.InternalReplicas))
127127
for _, repl := range desc.InternalReplicas {
128+
leaseDisp := mmaprototype.LeaseDispositionOK
129+
if repl.IsAnyVoter() && raftutil.ReplicaIsBehind(raftStatus, repl.ReplicaID) {
130+
// TODO: a follower for which we have developed a send queue will likely
131+
// be behind, but we could also explicitly use the send queue state to
132+
// inform the disposition below.
133+
leaseDisp = mmaprototype.LeaseDispositionRefusing
134+
}
128135
replica := mmaprototype.StoreIDAndReplicaState{
129136
StoreID: repl.StoreID,
130137
ReplicaState: mmaprototype.ReplicaState{
131-
VoterIsLagging: repl.IsAnyVoter() && raftutil.ReplicaIsBehind(raftStatus, repl.ReplicaID),
138+
LeaseDisposition: leaseDisp,
132139
ReplicaIDAndType: mmaprototype.ReplicaIDAndType{
133140
ReplicaID: repl.ReplicaID,
134141
ReplicaType: mmaprototype.ReplicaType{

0 commit comments

Comments
 (0)