Skip to content

removing generation state for deleted resources from memory #98

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

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ void scheduleEventFromApi(CustomResourceEvent event) {
try {
lock.lock();
log.debug("Scheduling event from Api: {}", event);
if (event.getResource().getMetadata().getDeletionTimestamp() != null && event.getAction() == Action.DELETED) {
// Note that we always use finalizers, we want to process delete event just in corner case,
// when we are not able to add finalizer (lets say because of optimistic locking error, and the resource was deleted instantly).
// We want to skip in case of finalizer was there since we don't want to execute delete method always at least 2x,
// which would be the result if we don't skip here. (there is no deletion timestamp if resource deleted without finalizer.)
log.debug("Skipping delete event since deletion timestamp is present on resource, so finalizer was in place.");
return;
if (event.getAction() == Action.DELETED) {
// This removes data from memory for deleted resource (prevent memory leak basically).
// Its quite interesting that this is always sufficient here (no finalizer or other mechanism needs to be involved).
// Thus, if operator is running we get DELETE the event, if not the memory is already gone anyways.
eventStore.removeLastGenerationForDeletedResource(event.resourceUid());
if (event.getResource().getMetadata().getDeletionTimestamp() != null) {
// Note that we always use finalizers, we want to process delete event just in corner case,
// when we are not able to add finalizer (lets say because of optimistic locking error, and the resource was deleted instantly).
// We want to skip in case of finalizer was there since we don't want to execute delete method always at least 2x,
// which would be the result if we don't skip here. (there is no deletion timestamp if resource deleted without finalizer.)
log.debug("Skipping delete event since deletion timestamp is present on resource, so finalizer was in place.");
return;
}
}
// In case of generation aware processing, we want to replace this even if generation not increased,
// to have the most recent copy of the event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ public boolean hasLargerGenerationThanLastStored(CustomResourceEvent event) {
public Long getLastStoredGeneration(CustomResourceEvent event) {
return lastGeneration.get(event.getResource().getMetadata().getUid());
}

public void removeLastGenerationForDeletedResource(String uuid) {
lastGeneration.remove(uuid);
}
}