From: Kevin Benton Date: Thu, 24 Dec 2015 08:54:06 +0000 (-0800) Subject: Call _allocate_vr_id outside of transaction X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=18e2117e3df3c119f843aed669d0c6bae9243053;p=openstack-build%2Fneutron-build.git 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 --- diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py index 01e979151..9bdf1227d 100644 --- a/neutron/db/l3_hamode_db.py +++ b/neutron/db/l3_hamode_db.py @@ -191,7 +191,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 @@ -224,9 +226,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 = {'network_id': network_id,