@@ -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.
21762168func (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