]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Avoid synchronizing session when deleting networkdhcpagentbinding
authorEugene Nikanorov <enikanorov@mirantis.com>
Tue, 7 Apr 2015 20:15:43 +0000 (00:15 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Wed, 8 Apr 2015 20:50:52 +0000 (23:50 +0300)
Synchronizing session on delete leads to traces in neutron-server
logs when such binding is deleted concurrently.
Also, catch and ignore ObjectDeletedError during iterating over
bindings, that is possible since the code is not within a transaction.

Change-Id: I7a2c9a8a59ce313c7d242230eeb5da69986bfbd4
Closes-Bug: #1424593

neutron/db/agentschedulers_db.py

index 39cb3eddd4852d60bbab974ccb4f4e8913f3a558..bbae44b358741802d68f9b17a536d4bd0d29d5cc 100644 (file)
@@ -228,19 +228,25 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
         # id -> is_agent_starting_up
         checked_agents = {}
         for binding in bindings:
-            agent_id = binding.dhcp_agent['id']
-            if agent_id not in checked_agents:
-                if self.agent_starting_up(context, binding.dhcp_agent):
-                    # When agent starts and it has many networks to process
-                    # it may fail to send state reports in defined interval.
-                    # The server will consider it dead and try to remove
-                    # networks from it.
-                    checked_agents[agent_id] = True
-                    LOG.debug("Agent %s is starting up, skipping", agent_id)
-                else:
-                    checked_agents[agent_id] = False
-            if not checked_agents[agent_id]:
-                yield binding
+            try:
+                agent_id = binding.dhcp_agent['id']
+                if agent_id not in checked_agents:
+                    if self.agent_starting_up(context, binding.dhcp_agent):
+                        # When agent starts and it has many networks to process
+                        # it may fail to send state reports in defined interval
+                        # The server will consider it dead and try to remove
+                        # networks from it.
+                        checked_agents[agent_id] = True
+                        LOG.debug("Agent %s is starting up, skipping",
+                                  agent_id)
+                    else:
+                        checked_agents[agent_id] = False
+                if not checked_agents[agent_id]:
+                    yield binding
+            except exc.ObjectDeletedError:
+                # we're not within a transaction, so object can be lost
+                # because underlying row is removed, just ignore this issue
+                LOG.debug("binding was removed concurrently, skipping it")
 
     def remove_networks_from_down_agents(self):
         """Remove networks from down DHCP agents if admin state is up.
@@ -363,7 +369,9 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
             for port in ports:
                 port['device_id'] = constants.DEVICE_ID_RESERVED_DHCP_PORT
                 self.update_port(context, port['id'], dict(port=port))
-            query.delete()
+            # avoid issues with query.one() object that was
+            # loaded into the session
+            query.delete(synchronize_session=False)
 
         if not notify:
             return