From 608b54137fb67512c07099089ea7e074176e12df Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 24 Dec 2015 00:54:06 -0800 Subject: [PATCH] Call _allocate_vr_id outside of transaction _allocate_vr_id is called from _set_vr_id, which was starting a transaction before calling it. This caused an error when the retry logic was triggered inside of _allocate_vr_id since it would encounter a DB exception and put the transaction into a bad state that couldn't be used on the retry. This patch just stops _set_vr_id from starting a transaction because it didn't serve a purpose. It also stops _allocate_vr_id from allowing subtransactions when it starts a transaction, since it's retry logic isn't compatible with them. Co-Authored-By: Ann Kamyshnikova Closes-Bug: #1528201 Change-Id: If7bcae39098f40f5ee9db78d3190bf9fdaf6438b (cherry picked from commit 18e2117e3df3c119f843aed669d0c6bae9243053) --- neutron/db/l3_hamode_db.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py index 31e9442a21f..ff015a254bb 100644 --- a/neutron/db/l3_hamode_db.py +++ b/neutron/db/l3_hamode_db.py @@ -181,7 +181,9 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin): def _allocate_vr_id(self, context, network_id, router_id): for count in range(MAX_ALLOCATION_TRIES): try: - with context.session.begin(subtransactions=True): + # NOTE(kevinbenton): we disallow subtransactions because the + # retry logic will bust any parent transactions + with context.session.begin(): allocated_vr_ids = self._get_allocated_vr_id(context, network_id) available_vr_ids = VR_ID_RANGE - allocated_vr_ids @@ -214,9 +216,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin): vr_id=vr_id).delete() def _set_vr_id(self, context, router, ha_network): - with context.session.begin(subtransactions=True): - router.extra_attributes.ha_vr_id = self._allocate_vr_id( - context, ha_network.network_id, router.id) + router.extra_attributes.ha_vr_id = self._allocate_vr_id( + context, ha_network.network_id, router.id) def _create_ha_subnet(self, context, network_id, tenant_id): args = {'subnet':