]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Call _allocate_vr_id outside of transaction
authorKevin Benton <blak111@gmail.com>
Thu, 24 Dec 2015 08:54:06 +0000 (00:54 -0800)
committerKevin Benton <blak111@gmail.com>
Thu, 24 Dec 2015 09:00:32 +0000 (01:00 -0800)
_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 <akamyshnikova@mirantis.com>
Closes-Bug: #1528201
Change-Id: If7bcae39098f40f5ee9db78d3190bf9fdaf6438b

neutron/db/l3_hamode_db.py

index 01e9791514ee6ee14b85c2f5b1f0bd5911392dd5..9bdf1227d989fdbca50e14256f54019841bd9919 100644 (file)
@@ -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,