@@ -1313,6 +1313,16 @@ func (rs *rangeState) removePendingChangeTracking(changeID changeID) {
13131313 }
13141314}
13151315
1316+ // clearAnalyzedConstraints clears the analyzed constraints for the range state.
1317+ // This should be used when rs is deleted or rs.constraints needs to be reset.
1318+ func (rs * rangeState ) clearAnalyzedConstraints () {
1319+ if rs .constraints == nil {
1320+ return
1321+ }
1322+ releaseRangeAnalyzedConstraints (rs .constraints )
1323+ rs .constraints = nil
1324+ }
1325+
13161326// clusterState is the state of the cluster known to the allocator, including
13171327// adjustments based on pending changes. It does not include additional
13181328// indexing needed for constraint matching, or for tracking ranges that may
@@ -1662,7 +1672,7 @@ func (cs *clusterState) processStoreLeaseholderMsgInternal(
16621672 // assuming the leaseholder wouldn't have sent the message if there was no
16631673 // change, or we noticed a divergence in membership above and fell through
16641674 // here.
1665- rs .constraints = nil
1675+ rs .clearAnalyzedConstraints ()
16661676 }
16671677 // Remove ranges for which this is the localRangeOwner, but for which it is
16681678 // no longer the leaseholder.
@@ -1703,6 +1713,7 @@ func (cs *clusterState) processStoreLeaseholderMsgInternal(
17031713 }
17041714 delete (cs .stores [replica .StoreID ].adjusted .replicas , r )
17051715 }
1716+ rs .clearAnalyzedConstraints ()
17061717 delete (cs .ranges , r )
17071718 }
17081719 localss := cs .stores [msg .StoreID ]
@@ -1961,7 +1972,7 @@ func (cs *clusterState) undoPendingChange(cid changeID) {
19611972 panic (errors .AssertionFailedf ("pending change is marked as no-rollback" ))
19621973 }
19631974 // Wipe the analyzed constraints, as the range has changed.
1964- rs .constraints = nil
1975+ rs .clearAnalyzedConstraints ()
19651976 rs .lastFailedChange = cs .ts .Now ()
19661977 // Undo the change delta as well as the replica change and remove the pending
19671978 // change from all tracking (range, store, cluster).
0 commit comments