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

Fix some memory leaks in TTL implementation #358

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

Woutifier
Copy link
Contributor

The aim of this PR is to resolve three issues with the Ristretto TTL implementation:

  • Expiry cleanup is not guaranteed to run, if it doesn't run when expected memory is leaked
  • expiryMap isn't cleared when cache is cleared
  • on Update items are added into the expiryMap even if they have no TTL set

@CLAassistant
Copy link

CLAassistant commented Sep 29, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

This PR has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.

@github-actions github-actions bot added the Stale label Jul 13, 2024
@Woutifier
Copy link
Contributor Author

Still relevant.

Should this project be archived, or marked as deprecated? These are serious issues that have gone unaddressed for a very long time.

@github-actions github-actions bot removed the Stale label Jul 14, 2024
@mangalaman93
Copy link
Contributor

Hi @Woutifier, Thanks for the PR and apologies for the delay. I am reviewing this PR on priority. Meanwhile, if you get a chance, feel free to merge/rebase with/on main.

Expiry cleanup is not guaranteed to run at any interval. It attemps to
run roughly twice per bucket duration, but may in fact not run.

If the cleanup does not run at least one per bucket duration, one or
more buckets may be leaked.

This commit adds a field lastCleanedBucketNum to the expirationMap to
keep track of the last bucket that was cleaned up. When cleanup is
called will clean up all the buckets between the last bucket and the
current bucket.
…o expiration

If an item was already in the cache, adding it again will cause it to be
added into the expiration map, even if the item has no expiration set.

This effectively is a memory leak. There is no clean up of this "zero
time" bucket, and it will keep growing.
@mangalaman93 mangalaman93 force-pushed the wouter/clear-expiry branch from ff4f885 to 371c81a Compare July 23, 2024 11:41
@mangalaman93 mangalaman93 requested a review from a team as a code owner July 23, 2024 11:41
@Woutifier
Copy link
Contributor Author

Thanks for taking this PR into consideration :-). Let me know if there's anything I can do to help

Copy link
Contributor

@mangalaman93 mangalaman93 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. Just one question, rest it is good to merge. Appreciate fixing this bug.

ttl.go Show resolved Hide resolved
@mangalaman93 mangalaman93 merged commit ff87317 into dgraph-io:main Jul 31, 2024
5 checks passed
mangalaman93 pushed a commit that referenced this pull request Dec 31, 2024
cleanup now does not try to clean an empty bucket selected by the
cleanup algorithm

this fixes a critical problem of slice growth when the algorithm
incorrectly calculates the buckets that need to be cleared, let's say
this behavior occurs at the time change described in issue:
#426

this problem appeared after improving cleanup in this pr:
#358

most likely the algorithm for calculating the cleaning bins also needs
to be revised, but for me now it is important to fix the increase in
memory consumption when changing the system time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants