-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #37785 - Race condition during container push
- Loading branch information
Showing
4 changed files
with
51 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/lib/actions/katello/repository/create_container_push_root.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Actions | ||
module Katello | ||
module Repository | ||
class CreateContainerPushRoot < Actions::EntryAction | ||
def plan(root, relative_path = nil) | ||
repository = ::Katello::Repository.new(:environment => root.organization.library, :content_view_version => root.organization.library.default_content_view_version, :root => root) | ||
#Container push may concurrently call root add several times before the db can update. | ||
# If the root already exists, we can skip the creation of the root and repository. | ||
# We acquire a lock on the product to ensure that the root is not created multiple times by different workers. | ||
|
||
root.product.with_lock do | ||
begin | ||
root.save! | ||
rescue ActiveRecord::RecordInvalid => e | ||
if root.is_container_push && e.message.include?("Name has already been taken for this product") | ||
Rails.logger.warn("Skipping root repository creation as container push root repository already exists: #{root.container_push_name}") | ||
return | ||
end | ||
raise e | ||
end | ||
repository.container_repository_name = relative_path if root.docker? && root.is_container_push | ||
repository.relative_path = relative_path || repository.custom_repo_path | ||
begin | ||
repository.save! | ||
rescue ActiveRecord::RecordInvalid => e | ||
if root.is_container_push && e.message.include?("Container Repository Name") && e.message.include?("conflicts with an existing repository") | ||
Rails.logger.warn("Skipping repository creation as container push repository already exists: #{root.container_push_name}") | ||
return | ||
end | ||
raise e | ||
end | ||
end | ||
|
||
action_subject(repository) | ||
plan_action(::Actions::Katello::Repository::Create, repository) | ||
end | ||
|
||
def humanized_name | ||
_("Create Container Push Repository Root") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters