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

sql: add accounting for entries in Txn Fingerprint ID cache #121956

Merged
merged 2 commits into from
Apr 9, 2024

Conversation

yuzefovich
Copy link
Member

This commit fixes a bug that could previously result in the memory accounting leak that was exposed by 88ebd70. Namely, the problem is that we previously unconditionally grew the memory account in Add even though if the ID is already present in the cache, it wouldn't be inserted again. As a result, we'd only shrink the account once but might have grown it any number of times for a particular ID. Now we check whether the ID is present in the cache and only grow the account if not.

Epic: None

Release note: None

This commit fixes a bug that could previously result in the memory
accounting leak that was exposed by 88ebd70.
Namely, the problem is that we previously unconditionally grew the
memory account in `Add` even though if the ID is already present in the
cache, it wouldn't be inserted again. As a result, we'd only shrink the
account once but might have grown it any number of times for
a particular ID. Now we check whether the ID is present in the cache and
only grow the account if not.

Epic: None

Release note: None
@yuzefovich yuzefovich requested review from DrewKimball and a team April 8, 2024 18:51
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich changed the title sql: fix accounting for entries in Txn Fingerprint ID cache sql: add accounting for entries in Txn Fingerprint ID cache Apr 8, 2024
Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice fix!

Reviewed 4 of 4 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/sql/txn_fingerprint_id_cache.go line 89 at r2 (raw file):

		// The value is already in the cache - do nothing.
		return nil
	}

BTW, there's also a Len() method we could use to update memory accounting without having to do anything in OnEvictedEntry. I'm fine with either method, though.

Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)


pkg/sql/txn_fingerprint_id_cache.go line 89 at r2 (raw file):

Previously, DrewKimball (Drew Kimball) wrote…

BTW, there's also a Len() method we could use to update memory accounting without having to do anything in OnEvictedEntry. I'm fine with either method, though.

Hm, I think we'd still need to set OnEvictedEntry in case the capacity of the cache is reduced. In other words, we'd use BoundAccount.ResizeTo in both Add and OnEvictedEntry which will be effectively the same as the current approach.

@DrewKimball
Copy link
Collaborator

Hm, I think we'd still need to set OnEvictedEntry in case the capacity of the cache is reduced. In other words, we'd use BoundAccount.ResizeTo in both Add and OnEvictedEntry which will be effectively the same as the current approach.

Right, good point.

@craig craig bot merged commit e9d1b46 into cockroachdb:master Apr 9, 2024
22 of 36 checks passed
@yuzefovich yuzefovich deleted the txn-cache-acc branch April 9, 2024 18:41
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.

None yet

3 participants