Skip to content

Commit 426ce7f

Browse files
committed
mma: fix a couple of todos related to changes
- subsumesChanges no longer needs the prev state as a parameter, since subsumption is only a function of the observed state and expected next state. The existing comparison with prev.IsLeaseholder was unnecessary and flawed. - Removed the todo around the panic in applyReplicaChange, since the expectation is that the range and store must exist. The callers are responsible for ensuring that. There was an old flawed idea that we would try to add the range at this point in the code, which we had long abandoned, but never removed from the code comment. Epic: CRDB-55052 Release note: None
1 parent b8111a6 commit 426ce7f

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

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

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ func (rit ReplicaIDAndType) String() string {
7575
return redact.StringWithoutMarkers(rit)
7676
}
7777

78-
// subsumesChange returns true if rit subsumes prev and next. prev is the state
79-
// before the proposed change and next is the state after the proposed change.
80-
// rit is the current observed state.
78+
// subsumesChange returns true if rit subsumes next, where next is the state
79+
// after the proposed change, and rit is the current observed state.
8180
//
8281
// NB: this method uses a value receiver since it mutates the value as part of
8382
// its computation.
84-
func (rit ReplicaIDAndType) subsumesChange(prev, next ReplicaIDAndType) bool {
83+
func (rit ReplicaIDAndType) subsumesChange(next ReplicaIDAndType) bool {
8584
if rit.ReplicaID == noReplicaID && next.ReplicaID == noReplicaID {
8685
// Removal has happened.
8786
return true
@@ -98,26 +97,18 @@ func (rit ReplicaIDAndType) subsumesChange(prev, next ReplicaIDAndType) bool {
9897
// been subsumed.
9998
switch rit.ReplicaType.ReplicaType {
10099
case roachpb.VOTER_INCOMING:
101-
// Already seeing the load, so consider the change done.
100+
// Already a voter, so consider the change done.
102101
rit.ReplicaType.ReplicaType = roachpb.VOTER_FULL
103102
}
104-
// rit.replicaType.ReplicaType equal to LEARNER, VOTER_DEMOTING* are left
105-
// as-is. If next is trying to remove a replica, this change has not
103+
// NB: rit.replicaType.ReplicaType equal to LEARNER, VOTER_DEMOTING* are
104+
// left as-is. If next is trying to remove a replica, this change has not
106105
// finished yet, and the store is still seeing the load corresponding to the
107-
// state it is exiting.
108-
109-
// TODO: the prev.IsLeaseholder == next.IsLeaseholder check originates in
110-
// the notion that if we were changing some aspect of ReplicaType, but not
111-
// whether it was the leaseholder, we could leave IsLeaseholder false in
112-
// both prev and next (signifying no change in this replica's leaseholder
113-
// bit). I think this is not actually true, and if it is, we should make it
114-
// not true. That is, we should populate all fields in prev and next,
115-
// regardless of whether they are changing or not. Additionally, it is hard
116-
// to fathom a change in the ReplicaType when it was a leaseholder and is
117-
// staying a leaseholder.
106+
// state it is exiting. If next is trying to demote to a NON_VOTER, but
107+
// rit.ReplicaType.ReplicaType is equal to VOTER_DEMOTING_NON_VOTER, then it
108+
// is still a voter, so the change is not yet done.
109+
118110
if rit.ReplicaType.ReplicaType == next.ReplicaType.ReplicaType &&
119-
(prev.IsLeaseholder == next.IsLeaseholder ||
120-
rit.IsLeaseholder == next.IsLeaseholder) {
111+
rit.IsLeaseholder == next.IsLeaseholder {
121112
return true
122113
}
123114
return false
@@ -1544,7 +1535,7 @@ func (cs *clusterState) processStoreLeaseholderMsgInternal(
15441535
if !ok {
15451536
adjustedReplica.ReplicaID = noReplicaID
15461537
}
1547-
if adjustedReplica.subsumesChange(change.prev.ReplicaIDAndType, change.next) {
1538+
if adjustedReplica.subsumesChange(change.next) {
15481539
// The change has been enacted according to the leaseholder.
15491540
enactedChanges = append(enactedChanges, change)
15501541
} else {
@@ -2173,19 +2164,14 @@ func (cs *clusterState) preCheckOnUndoReplicaChanges(changes []*pendingReplicaCh
21732164
return nil
21742165
}
21752166

2167+
// REQUIRES: the range and store are known to the allocator.
21762168
func (cs *clusterState) applyReplicaChange(change ReplicaChange, applyLoadChange bool) {
21772169
storeState, ok := cs.stores[change.target.StoreID]
21782170
if !ok {
21792171
panic(fmt.Sprintf("store %v not found in cluster state", change.target.StoreID))
21802172
}
21812173
rangeState, ok := cs.ranges[change.rangeID]
21822174
if !ok {
2183-
// This is the first time encountering this range, we add it to the cluster
2184-
// state.
2185-
//
2186-
// TODO(kvoli): Pass in the range descriptor to construct the range state
2187-
// here. Currently, when the replica change is a removal this won't work
2188-
// because the range state will not contain the replica being removed.
21892175
panic(fmt.Sprintf("range %v not found in cluster state", change.rangeID))
21902176
}
21912177

0 commit comments

Comments
 (0)