Skip to content

Conversation

@wenyihu6
Copy link
Contributor

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.

@wenyihu6 wenyihu6 requested review from a team as code owners November 19, 2025 14:25
@blathers-crl
Copy link

blathers-crl bot commented Nov 19, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@wenyihu6 wenyihu6 requested review from sumeerbhola and tbg November 19, 2025 14:25
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@tbg reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @sumeerbhola)


-- commits line 5 at r1:
Could it leak? Releasing them puts them back into the pool, but they should otherwise have gotten garbage collected.

Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sumeerbhola reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @wenyihu6)


pkg/kv/kvserver/allocator/mmaprototype/cluster_state.go line 1665 at r1 (raw file):

		// change, or we noticed a divergence in membership above and fell through
		// here.
		releaseRangeAnalyzedConstraints(rs.constraints)

nit: can we make a method on rangeState called clearAnalyzedConstraints that both sets rs.constraints to nil and calls releaseRangeAnalyzedConstraints. I am nervous about multiple places remembering to do both.


pkg/kv/kvserver/allocator/mmaprototype/cluster_state.go line 1665 at r1 (raw file):

		// change, or we noticed a divergence in membership above and fell through
		// here.
		releaseRangeAnalyzedConstraints(rs.constraints)

releaseRangeAnalyzedConstraints assumes the parameter is non-nil. It isn't clear all these callers satisfy that constraint.


pkg/kv/kvserver/allocator/mmaprototype/cluster_state.go line 1707 at r1 (raw file):

			delete(cs.stores[replica.StoreID].adjusted.replicas, r)
		}
		releaseRangeAnalyzedConstraints(rs.constraints)

this case would also call the aforementioned method.

Copy link
Contributor Author

@wenyihu6 wenyihu6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @sumeerbhola and @tbg)


-- commits line 5 at r1:

Previously, tbg (Tobias Grieger) wrote…

Could it leak? Releasing them puts them back into the pool, but they should otherwise have gotten garbage collected.

I was thinking of not returning something to the pool as a resource leak, but I’m not sure if that’s the right terminology. I rephrased it as not putting things back into the pool.


pkg/kv/kvserver/allocator/mmaprototype/cluster_state.go line 1665 at r1 (raw file):

Previously, sumeerbhola wrote…

nit: can we make a method on rangeState called clearAnalyzedConstraints that both sets rs.constraints to nil and calls releaseRangeAnalyzedConstraints. I am nervous about multiple places remembering to do both.

Good call, done.


pkg/kv/kvserver/allocator/mmaprototype/cluster_state.go line 1665 at r1 (raw file):

Previously, sumeerbhola wrote…

releaseRangeAnalyzedConstraints assumes the parameter is non-nil. It isn't clear all these callers satisfy that constraint.

Good call, there were panics. Fixed.


pkg/kv/kvserver/allocator/mmaprototype/cluster_state.go line 1707 at r1 (raw file):

Previously, sumeerbhola wrote…

this case would also call the aforementioned method.

Done.

@wenyihu6 wenyihu6 requested a review from sumeerbhola November 19, 2025 17:04
Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@sumeerbhola reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @tbg)

Previously, releaseRangeAnalyzedConstraints was not called on
rangeAnalyzedConstraints, which could hold onto them and not returning to the
pool. This commit ensures they are released whenever unused.
@wenyihu6
Copy link
Contributor Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Nov 19, 2025

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@craig
Copy link
Contributor

craig bot commented Nov 19, 2025

@craig craig bot merged commit f87a3c8 into cockroachdb:master Nov 19, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants