From d04335c448aa15cf9e1902e22ed4cd17b6ed344b Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 16 Jul 2015 02:07:48 -0700 Subject: [PATCH] Add oslo db retry decorator to non-CRUD actions The previously added decorators to the create and update handlers in the API layer only applied to actions that followed the standard create/update path. However, for API operations like add_router_interface, a different path is followed that wasn't covered by a retry decorator. This patch adds the decorator to handle deadlocks in those operations as well. Closes-Bug: #1475218 Change-Id: Ib354074e6a3f68cedb95fd774f905d94ca16a830 --- neutron/api/v2/base.py | 13 +++++-------- neutron/db/api.py | 3 +++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/neutron/api/v2/base.py b/neutron/api/v2/base.py index 48dea6bf6..edae5b1f1 100644 --- a/neutron/api/v2/base.py +++ b/neutron/api/v2/base.py @@ -17,7 +17,6 @@ import copy import netaddr from oslo_config import cfg -from oslo_db import api as oslo_db_api from oslo_log import log as logging from oslo_policy import policy as oslo_policy from oslo_utils import excutils @@ -187,6 +186,7 @@ class Controller(object): def __getattr__(self, name): if name in self._member_actions: + @db_api.retry_db_errors def _handle_action(request, id, **kwargs): arg_list = [request.context, id] # Ensure policy engine is initialized @@ -197,7 +197,7 @@ class Controller(object): except oslo_policy.PolicyNotAuthorized: msg = _('The resource could not be found.') raise webob.exc.HTTPNotFound(msg) - body = kwargs.pop('body', None) + body = copy.deepcopy(kwargs.pop('body', None)) # Explicit comparison with None to distinguish from {} if body is not None: arg_list.append(body) @@ -383,8 +383,7 @@ class Controller(object): # We need a way for ensuring that if it has been created, # it is then deleted - @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES, - retry_on_deadlock=True) + @db_api.retry_db_errors def create(self, request, body=None, **kwargs): """Creates a new instance of the requested entity.""" parent_id = kwargs.get(self._parent_id_name) @@ -470,8 +469,7 @@ class Controller(object): return notify({self._resource: self._view(request.context, obj)}) - @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES, - retry_on_deadlock=True) + @db_api.retry_db_errors def delete(self, request, id, **kwargs): """Deletes the specified entity.""" self._notifier.info(request.context, @@ -506,8 +504,7 @@ class Controller(object): result, notifier_method) - @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES, - retry_on_deadlock=True) + @db_api.retry_db_errors def update(self, request, id, body=None, **kwargs): """Updates the specified entity's attributes.""" parent_id = kwargs.get(self._parent_id_name) diff --git a/neutron/db/api.py b/neutron/db/api.py index 0b68bd331..dec09bd35 100644 --- a/neutron/db/api.py +++ b/neutron/db/api.py @@ -17,6 +17,7 @@ import contextlib import six from oslo_config import cfg +from oslo_db import api as oslo_db_api from oslo_db import exception as os_db_exception from oslo_db.sqlalchemy import session from sqlalchemy import exc @@ -26,6 +27,8 @@ from sqlalchemy import orm _FACADE = None MAX_RETRIES = 10 +retry_db_errors = oslo_db_api.wrap_db_retry(max_retries=MAX_RETRIES, + retry_on_deadlock=True) def _create_facade_lazily(): -- 2.45.2