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

Add pre delete hook to domain for orphans #3801

Merged
merged 1 commit into from May 15, 2023

Conversation

mdellweg
Copy link
Member

@mdellweg mdellweg commented May 8, 2023

fixes #3800

@mdellweg mdellweg force-pushed the orphan_delete_domain branch 2 times, most recently from 2263b98 to 6b308e0 Compare May 8, 2023 12:41
@mdellweg mdellweg marked this pull request as ready for review May 8, 2023 13:02
@@ -49,6 +49,15 @@ def get_storage(self):
def prevent_default_deletion(self):
raise models.ProtectedError("Default domain can not be updated/deleted.", [self])

@hook(BEFORE_DELETE, when="name", is_not="default")
def _cleanup_orphans_pre_delete(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This delete is expected to happen inside of a task, not the API, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely. You are supposed to hold the exclusive domain lock for it.

self.content_set.filter(version_memberships__isnull=True).delete()
for artifact in self.artifact_set.all().iterator():
# Delete on by one to properly cleanup the storage.
artifact.delete()
Copy link
Contributor

@dralley dralley May 10, 2023

Choose a reason for hiding this comment

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

It would be nice if we could submit these deletions to a threadpool, or use async, or anything which would speed up the process relative to a sequential synchronous delete.

But that's a suggestion for another time.

@mdellweg
Copy link
Member Author

I'm not so sure, should this be a bugfix?

@dralley
Copy link
Contributor

dralley commented May 15, 2023

It could make sense as a bugfix - maybe go ahead and do this if you think we may need to backport it?

@mdellweg
Copy link
Member Author

Let's not do it for the sake of backporting... You can still issue an orphan cleanup prior to deleting the domain. So there's a rather easy workaround.

@mdellweg mdellweg merged commit 686e29f into pulp:main May 15, 2023
15 checks passed
def _cleanup_orphans_pre_delete(self):
if self.content_set.exclude(version_memberships__isnull=True).exists():
raise models.ProtectedError("There is active content in the domain.")
self.content_set.filter(version_memberships__isnull=True).delete()
Copy link
Member

Choose a reason for hiding this comment

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

i might be throwing a wrench in here.. but the criteria for the orphaned content/artifacts consists not only in the membership but also in the protection time https://github.com/pulp/pulpcore/blob/main/pulpcore/app/models/content.py#L176

Copy link
Member Author

Choose a reason for hiding this comment

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

I know, but at this point, you intend to delete the domain (now) which would fail if anything useful (like repositories) is left. And in that condition no artifact will be deleted either. I believe it is safe to assume that at this point we do not need to wait for any expiry anymore.

Copy link
Member

Choose a reason for hiding this comment

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

I understand what you're saying and it probably does sound logical and desirable, it's just here we're changing the concept of what an 'orphan' means. I know that right now i am being overly picky, however, same logic could be applicable to 'i want to delete the content (now) but.. oh wait..it has protection time'.

As long as it was on purpose, it's ok just leaving an explicit note on the code would have been helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, i should have added a comment. It was too obvious to me. To be fair, the protection time is not on the content, but you can provide the protection time with the delete orphan call. So you can delete your content "now" if you intend to.

@mdellweg mdellweg deleted the orphan_delete_domain branch May 15, 2023 14:50
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.

Orphaned content should not prevent to delete a domain.
4 participants