-
Notifications
You must be signed in to change notification settings - Fork 289
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
Fixes #36563 - Remove orphaned content unit cleanup from index_content #10638
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Actions | ||
module Katello | ||
module OrphanCleanup | ||
class RemoveOrphanedContentUnits < Actions::Base | ||
def plan(options = {}) | ||
plan_self(id: options[:repo_id], destroy_all: options[:destroy_all]) | ||
end | ||
|
||
def run | ||
content_types_to_index = [] | ||
if input[:destroy_all] | ||
::Katello::RepositoryTypeManager.enabled_repository_types.each_value do |repo_type| | ||
content_types_to_index << repo_type.content_types_to_index | ||
end | ||
elsif input[:id] | ||
repo = ::Katello::Repository.find(input[:id]) | ||
content_types_to_index = repo.repository_type.content_types_to_index | ||
else | ||
fail "Pass either a repository to determine content type or destroy_all to destroy all orphaned content units" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about removing the |
||
end | ||
content_types_to_index.flatten.each do |type| | ||
type.model_class.orphaned.destroy_all | ||
end | ||
end | ||
|
||
def rescue_strategy | ||
Dynflow::Action::Rescue::Skip | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,27 +7,16 @@ class RemoveOrphans < Actions::Base | |
end | ||
def plan(proxy) | ||
sequence do | ||
if proxy.pulp_primary? | ||
::Katello::RootRepository.orphaned.destroy_all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why this was pulled out of the run phase? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really..This was the only operation in the run phase after refactoring the content unit deletion..and this doesn't seem like something that needs to be in the run phase.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's a DB operation, should try not to put it in the run phase because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't a heavy DB operation in the planning phase eat up a Puma worker? Also we shouldn't need transactions here at least since we're deleting orphans. But even if we did need one, couldn't we do a (I don't think deleting orphaned root repos will be a heavy operation, but I'm a little confused because we stick heavy DB ops in tasks in other places) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Usually they're in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack to that..We tend to put only things that need API calls to other products in run phase generally. For this task, I'd be ok keeping this in run phase over the plan phase. Any failures on this are set to rescue=skip and also we do want to still plan other pulp orphan deletion actions even if the orphan deletion in katello fails. A plan phase failure wouldn't plan those pulp tasks. We could put this in finalize if we want. Let me know if we feel strongly about that and I can update this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me. I trust your judgment to choose the phase correctly :) |
||
plan_action(RemoveOrphanedContentUnits, destroy_all: true) | ||
end | ||
if proxy.pulp3_enabled? | ||
plan_action( | ||
Actions::Pulp3::Orchestration::OrphanCleanup::RemoveOrphans, | ||
proxy) | ||
end | ||
plan_self | ||
end | ||
end | ||
|
||
def run | ||
models = [] | ||
::Katello::RepositoryTypeManager.enabled_repository_types.each_value do |repo_type| | ||
indexable_types = repo_type.content_types_to_index | ||
models += indexable_types&.map(&:model_class) | ||
models.select! { |model| model.many_repository_associations } | ||
end | ||
models.each do |model| | ||
model.joins("left join katello_#{model.repository_association} on #{model.table_name}.id = katello_#{model.repository_association}.#{model.unit_id_field}").where("katello_#{model.repository_association}.#{model.unit_id_field} IS NULL").destroy_all | ||
end | ||
|
||
::Katello::RootRepository.orphaned.destroy_all | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -31,6 +31,10 @@ def run | |||
output[:new_content][content_type.label] = new_count - initial_counts[content_type.label] | ||||
end | ||||
end | ||||
|
||||
def finalize | ||||
ForemanTasks.async_task(OrphanCleanup::RemoveOrphanedContentUnits, {repo_id: input[:id]}) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm questioning now if we even need to destroy orphaned units after syncing. For the orphaned filter rule problem, the solution is this:
Otherwise, I don't think orphaned content units should cause any other problems. Plus, if a user syncs 20 repositories, they're going to get 20 orphan cleanup tasks running, which could eat up resources on their system. Perhaps we should just rely on the weekly orphan cleanup? If we do that, I just suggest that we change the following error messages to tell the users to run orphan cleanup instead of run a complete sync: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, maybe we should change those error messages with your PR here regardless. Complete sync no longer deletes the orphaned units itself. |
||||
end | ||||
end | ||||
end | ||||
end | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'katello_test_helper' | ||
module Katello | ||
class RemoveOrphanedContentUnitsTest < ActiveSupport::TestCase | ||
def setup | ||
@rhel6 = Repository.find(katello_repositories(:rhel_6_x86_64).id) | ||
end | ||
|
||
def test_orphaned_content_task_destroys_orphans | ||
rpm = katello_rpms(:one) | ||
rpm.repository_rpms.destroy_all | ||
ForemanTasks.sync_task(Actions::Katello::OrphanCleanup::RemoveOrphanedContentUnits, {repo_id: @rhel6.id}) | ||
assert_raises(ActiveRecord::RecordNotFound) { rpm.reload } | ||
end | ||
|
||
def test_orphaned_content_task_destroy_all | ||
rpm = katello_rpms(:one) | ||
rpm.repository_rpms.destroy_all | ||
ForemanTasks.sync_task(Actions::Katello::OrphanCleanup::RemoveOrphanedContentUnits, {destroy_all: true}) | ||
assert_raises(ActiveRecord::RecordNotFound) { rpm.reload } | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content_types_to_index
makes it sound a bit like the types will be indexed instead of checked for orphans.