From c8918b4194d51c5805a64968fdf7a67686fc0994 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 27 Mar 2018 16:09:13 -0700 Subject: [PATCH] Add deadlock retry wrapper for inital quota create Since the initial quota record creation is using the autocommit session and since it is creating the initial record, it will lock at the table(index) level instead of at the record level. This can lead to a recoverable DB Deadlock situation. This was observed running the neutron-lbaas API tempest tests with concurrency greater than 1. This patch adds the oslo DB deadlock retry wrapper to this initial record creation to allow deadlock recovery. Change-Id: Ibbfa77f548fead3203cf081e203c5e70fe514111 --- octavia/db/repositories.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/octavia/db/repositories.py b/octavia/db/repositories.py index 6989a66c35..a54c77926b 100644 --- a/octavia/db/repositories.py +++ b/octavia/db/repositories.py @@ -21,6 +21,7 @@ reference import datetime from oslo_config import cfg +from oslo_db import api as oslo_db_api from oslo_db import exception as db_exception from oslo_log import log as logging from oslo_utils import excutils @@ -1307,6 +1308,12 @@ class L7PolicyRepository(BaseRepository): class QuotasRepository(BaseRepository): model_class = models.Quotas + # This is used with an autocommit session (non-lock_session) + # Since this is for the initial quota record creation it locks the table + # which can lead to recoverable deadlocks. Thus we use the deadlock + # retry wrapper here. This may not be appropriate for other sessions + # and or queries. Use with caution. + @oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True) def update(self, session, project_id, **model_kwargs): with session.begin(subtransactions=True): kwargs_quota = model_kwargs['quota']