Skip to content

Commit f87a3c8

Browse files
craig[bot]wenyihu6
andcommitted
Merge #158048
158048: mmaprototype: release rangeAnalyzedConstraints properly r=wenyihu6 a=wenyihu6 Epic: CRDB-55052 Release note: none --- **mmaprototype: release rangeAnalyzedConstraints properly** Previously, we weren’t calling releaseRangeAnalyzedConstraints on rangeAnalyzedConstraints, which could lead to resource leak. This commit calls releaseRangeAnalyzedConstraints when they are unused. Co-authored-by: wenyihu6 <[email protected]>
2 parents a0b2049 + 0b101fd commit f87a3c8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)