Skip to content

Commit

Permalink
[resolver] Make dependency_cache.get_or_create_nevra concurrency-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
msimacek committed Feb 13, 2018
1 parent 32d19c1 commit 1ea3e5d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions koschei/backend/services/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from sqlalchemy.orm import undefer
from sqlalchemy.sql import insert
from sqlalchemy.exc import IntegrityError

from koschei import util
from koschei.config import get_config
Expand Down Expand Up @@ -65,7 +66,7 @@ def _compact(self):
del self.nevras[(victim.name, victim.epoch, victim.version,
victim.release, victim.arch)]

def get_or_create_nevra(self, db, nevra):
def _get_or_create_nevra(self, db, nevra):
dep = self.nevras.get(nevra)
if dep is None:
dep = db.query(*Dependency.inevra)\
Expand All @@ -87,10 +88,18 @@ def get_or_create_nevra(self, db, nevra):
self._access(dep)
return dep

def get_or_create_nevra(self, db, nevra):
try:
with db.begin_nested():
return self._get_or_create_nevra(db, nevra)
except IntegrityError:
# If there was a concurrent insert, the next query must succeed
return self._get_or_create_nevra(db, nevra)

def get_or_create_nevras(self, db, nevras):
res = []
for nevra in nevras:
res.append(self.get_or_create_nevra(db, nevra))
res.append(self._get_or_create_nevra(db, nevra))
return res

@stopwatch(total_time, note='dependency cache')
Expand Down

0 comments on commit 1ea3e5d

Please sign in to comment.