Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: refactor race-build file cache reference tracking #4362

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Mar 5, 2025

Previously the file cache used a pointer to the sstable iterator to maintain the stack traces of the origination of open references during race builds. This was a bit ambiguous. With the introduction of blob files, references will also be maintained by non-sstable iterators (eg, a cached blob file reader within an iterator's blob value fetcher).

This commit refactors this reference tracking to propagate a uint64 reference ID along with the closeHook, requiring the user to pass the reference ID back in their invocation of the closeHook. In production builds, this reference ID is always zero and is not stored. This hopefully will make usages unambiguous.

@jbowens jbowens requested a review from a team as a code owner March 5, 2025 16:13
@jbowens jbowens requested a review from RaduBerinde March 5, 2025 16:13
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde 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: 0 of 4 files reviewed, 2 unresolved discussions


file_cache.go line 113 at r1 (raw file):

		nextRefID uint64
		// openRefs maps reference IDs to the stack trace recorded at creation
		// time.  It's used to track which call paths leaked open references to

[nit] double space


file_cache.go line 590 at r1 (raw file):

) (refID uint64, closeHook func(refID uint64)) {
	h.iterCount.Add(1)
	if invariants.RaceEnabled {

It would be a lot cleaner if we just generated a new closeHook here in race mode, so we don't have to plumb the refID around. I don't think the allocation is a problem in race mode, which is terribly slow anyway.

Previously the file cache used a pointer to the sstable iterator to maintain
the stack traces of the origination of open references during race builds. This
was a bit ambiguous. With the introduction of blob files, references will also
be maintained by non-sstable iterators (eg, a cached blob file reader within an
iterator's blob value fetcher).

This commit refactors this reference tracking to allocate a new closure in race
builds. The additional allocation is expected to be significant in (already
slow) race builds.
Copy link
Collaborator Author

@jbowens jbowens 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: 0 of 4 files reviewed, 2 unresolved discussions (waiting on @RaduBerinde)


file_cache.go line 590 at r1 (raw file):

Previously, RaduBerinde wrote…

It would be a lot cleaner if we just generated a new closeHook here in race mode, so we don't have to plumb the refID around. I don't think the allocation is a problem in race mode, which is terribly slow anyway.

Genius

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 4 files at r2.
Reviewable status: all files reviewed (commit messages unreviewed), 2 unresolved discussions (waiting on @jbowens)

@jbowens jbowens merged commit 95ffb4a into cockroachdb:master Mar 5, 2025
23 checks passed
@jbowens jbowens deleted the filecache-refid branch March 5, 2025 23:09
@jbowens
Copy link
Collaborator Author

jbowens commented Mar 5, 2025

TFTR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants