From 5c7e20a742aa828da64771e47b7a05c72cb4c71c Mon Sep 17 00:00:00 2001 From: Alexander Tivelkov Date: Thu, 8 Oct 2015 15:43:31 +0300 Subject: [PATCH] Retry-on-deadlock added to modify package db api On some HA database deployments such as MySQL Galera the transaction locks are optimistic, and if the same data gets modifyed concurrently DB server may throw a DBDeadlock error which is intended to be handled by the caller app. This patch adds appropriate retrying logic into the catalog db api methods, so the operation to upload, modify or delete the package gets retryed if the deadlock occurs due to this optimistic locking behavior. It uses oslo_db_api.wrap_db_retry helper decorator from oslo library. Closes-Bug: #1502589 Change-Id: I8d7b3dfb02a31eba6d55ba0bf89ac0cf05f1313d --- murano/db/catalog/api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/murano/db/catalog/api.py b/murano/db/catalog/api.py index 71388a3a..4eaea081 100644 --- a/murano/db/catalog/api.py +++ b/murano/db/catalog/api.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from oslo_db import api as oslo_db_api from oslo_db.sqlalchemy import utils from oslo_log import log as logging import sqlalchemy as sa @@ -214,6 +215,7 @@ def _get_packages_for_category(session, category_id): return result_packages +@oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True) def package_update(pkg_id_or_name, changes, context): """Update package information :param changes: parameters to update @@ -343,6 +345,7 @@ def package_search(filters, context, manage_public=False, return query.all() +@oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True) def package_upload(values, tenant_id): """Upload a package with new application :param values: parameters describing the new package @@ -388,6 +391,7 @@ def package_upload(values, tenant_id): return package +@oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True) def package_delete(package_id, context): """Delete a package by ID.""" session = db_session.get_session()