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: using tombstones to account for rapid deletion #2317

Merged
merged 1 commit into from Mar 27, 2024

Conversation

shawkins
Copy link
Collaborator

closes: #2314

If during a creation the events for both the add and the deletion occur before the resource is being added to the temporary cache, the temporary cache moves backwards in a way that may not resolve itself.

The approach here is to use tombstones to track deletions. The benefit of this approach is that it keeps the logic encapsulated to the TemporaryResourceCache. The drawback is that we're only guessing about how long to retain the tombstones.

The other approach would look more similar to event recording, which is notify the cache that a create is happening prior to when it starts so that deletions / tombstones can gathered for that specific resource.

synchronized void onEvent(T resource, boolean unknownState) {
if (!tombstones.isEmpty()) {
var iter = tombstones.entrySet().iterator();
var entry = iter.next();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if understand this part, it always removes one random event from the tombstone if expired? Didn't you mean to iterate over all events?

Copy link
Collaborator Author

@shawkins shawkins Mar 26, 2024

Choose a reason for hiding this comment

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

No, this is to amortorize the expiration logic - you could of course decide on a greater number than 1. Since it's a linked hashmap it's not a random entry.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe desribe in there as a comment too, that is intentional, since I will at least naivly stop on this every time I open it :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to see this as a comment, indeed, as well.

synchronized void onEvent(T resource, boolean unknownState) {
if (!tombstones.isEmpty()) {
var iter = tombstones.entrySet().iterator();
var entry = iter.next();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to see this as a comment, indeed, as well.

Copy link
Collaborator

@metacosm metacosm left a comment

Choose a reason for hiding this comment

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

LGTM apart from missing comment explaining the amortization of cache emptying logic

closes: operator-framework#2314

Signed-off-by: Steven Hawkins <shawkins@redhat.com>
@shawkins
Copy link
Collaborator Author

@metacosm @metacosm updated the code with further comments and consolidated the secondary caching concerns to a single class. From what I can tell it will take around 170 MB to track up to 1000000 deletions. Also updated the base retention time to 10 minutes, rather than 2. Based upon seeing what the retained heap size of this could be, I also updated the knownResourceVersions cache to be able to store more entries.

@csviri csviri merged commit 3bfac63 into operator-framework:main Mar 27, 2024
20 checks passed
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.

Suspected timing issue around temporary cache and garbage collection of resources
3 participants