Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Resolve race condition during applicability generation
Browse files Browse the repository at this point in the history
Race condition was possible when applicability generation was running
in parallel for the same consumer profiles.

closes #2874
https://pulp.plan.io/issues/2874
  • Loading branch information
goosemania committed Jul 21, 2017
1 parent fe46fee commit 7a90d86
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions server/pulp/server/managers/consumer/applicability.py
Expand Up @@ -7,6 +7,7 @@
from uuid import uuid4

from celery import task
from pymongo.errors import DuplicateKeyError

from pulp.plugins.conduits.profiler import ProfilerConduit
from pulp.plugins.config import PluginCallConfiguration
Expand Down Expand Up @@ -260,16 +261,20 @@ def regenerate_applicability(profile_hash, content_type, profile_id,
_logger.debug(msg)
return

if existing_applicability:
# Update existing applicability object
existing_applicability.applicability = applicability
existing_applicability.save()
else:
try:
# Create a new RepoProfileApplicability object and save it in the db
RepoProfileApplicability.objects.create(profile_hash,
bound_repo_id,
unit_profile['profile'],
profile,
applicability)
except DuplicateKeyError:
# Update existing applicability
if not existing_applicability:
applicability_dict = RepoProfileApplicability.get_collection().find_one(
{'repo_id': bound_repo_id, 'profile_hash': profile_hash})
existing_applicability = RepoProfileApplicability(**applicability_dict)
existing_applicability.applicability = applicability
existing_applicability.save()

@staticmethod
def _get_existing_repo_content_types(repo_id):
Expand Down Expand Up @@ -456,6 +461,8 @@ def remove_orphans():
# Remove all RepoProfileApplicability objects that reference these profile hashes
if missing_profile_hashes:
rpa_collection.remove({'profile_hash': {'$in': missing_profile_hashes}})


# Instantiate one of the managers on the object it manages for convenience
RepoProfileApplicability.objects = RepoProfileApplicabilityManager()

Expand Down

0 comments on commit 7a90d86

Please sign in to comment.