Can not delete images if db deadlock occurs

Glance api returns 500 Internal Server Error, if db deadlock occurs
in glance-registry for some reason while deleting an image.

Added retry on image_destroy when db deadlock occures which will again
try to delete the image from database.

Closes-bug: 1378215
Change-Id: Ifad403e363daf368e846b5b6838432a7bedbe81a
(cherry picked from commit dae0fa8f10)
This commit is contained in:
ankitagrawal 2014-10-07 07:36:10 -07:00 committed by Abhishek Kekane
parent e58013c2c0
commit 41e143b217
2 changed files with 12 additions and 0 deletions

View File

@ -135,6 +135,8 @@ def image_update(context, image_id, values, purge_props=False,
from_state=from_state)
@retry(retry_on_exception=_retry_on_deadlock, wait_fixed=500,
stop_max_attempt_number=50)
def image_destroy(context, image_id):
"""Destroy the image or raise if it does not exist."""
session = get_session()

View File

@ -717,3 +717,13 @@ class RetryOnDeadlockTestCase(test_utils.BaseTestCase):
api._image_update(None, {}, 'fake-id')
except TestException:
self.assertEqual(sess.call_count, 3)
# Test retry on image destroy if db deadlock occurs
self.attempts = 3
with mock.patch.object(api, 'get_session') as sess:
sess.side_effect = _mock_get_session()
try:
api.image_destroy(None, 'fake-id')
except TestException:
self.assertEqual(sess.call_count, 3)