Commit 772f9100 authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

add version state 'replaced'

to avoid race conditions on ImageManager.push()
(the function would fail if the version db row is deleted immediately)
parent 3ea9fad4
......@@ -1164,7 +1164,7 @@ class PushManager(Manager):
# get the version object and check its state
version = ses.query(WebappVersion).filter_by(id=version_id).one()
if version.state != VersionState.committed:
if version.state == VersionState.ready:
if version.state in (VersionState.ready, VersionState.replaced):
# already pushed
return
if version.state == VersionState.sandbox:
......@@ -1196,13 +1196,21 @@ class PushManager(Manager):
if prev is None:
# this is a new version
version.state = VersionState.ready
version.state = int(VersionState.ready)
else:
# overwrite an existing version
for key in "updated_at", "changelog", "published":
setattr(prev, key, getattr(version, key))
ses.delete(version)
# TODO get rid of this 'replaced' state (and delete the record immediately)
# The 'replaced' state was introduced to avoid a race condition
# if multiple tasks are calling push() concurrently. If
# the version row is deleted, then the second call to push()).
# However this 'replaced' state does not need to be
# written to the db (because is only important for the
# running controller process). We could use another way
# of storing this state.
version.state = int(VersionState.replaced)
class ImageManager:
......@@ -1243,7 +1251,7 @@ class ImageManager:
with ses.begin():
version = ses.query(WebappVersion).filter_by(id=version_id).one()
if version.state != VersionState.ready:
if version.state not in (VersionState.ready, VersionState.replaced):
raise Error("bad version state: %s" % version.state)
yield from self.swarm_pull_manager.process((image, tag))
......@@ -1254,7 +1262,7 @@ class ImageManager:
# do not pull!
return
if version.state != VersionState.ready:
if version.state not in (VersionState.ready, VersionState.replaced):
raise Error("bad version state: %s" % version.state)
yield from self.sandbox_pull_manager.process((image, tag))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment