]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
L3 DB: Defer port DB subnet lookups
authorKevin Benton <blak111@gmail.com>
Fri, 17 Apr 2015 11:46:11 +0000 (04:46 -0700)
committerKevin Benton <blak111@gmail.com>
Tue, 21 Apr 2015 09:32:13 +0000 (02:32 -0700)
_populate_subnets_for_ports was being called multiple
times for different interface types during the get_routers
process.

This patch eliminates those extra queries by deferring the
subnet information population until after all of the interfaces
have been looked up. Includes a function rename as well to
indicate that a function is only used internally.

Change-Id: Ib46f685d72eb61ecbaa2869e28fb173cd6d49552
Partial-bug: #1445412

neutron/db/l3_db.py
neutron/db/l3_dvr_db.py

index 501723308b62bf749cc368b24466192113ab0d61..04446e7137effcada1ce42ea10329b91b720cd7c 100644 (file)
@@ -1119,8 +1119,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
         if gw_port_ids:
             gw_ports = dict((gw_port['id'], gw_port)
                             for gw_port in
-                            self.get_sync_gw_ports(context, gw_port_ids))
-        # NOTE(armando-migliaccio): between get_routers and get_sync_gw_ports
+                            self._get_sync_gw_ports(context, gw_port_ids))
+        # NOTE(armando-migliaccio): between get_routers and _get_sync_gw_ports
         # gw ports may get deleted, which means that router_dicts may contain
         # ports that gw_ports does not; we should rebuild router_dicts, but
         # letting the callee check for missing gw_ports sounds like a good
@@ -1133,16 +1133,14 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
             return []
         return self.get_floatingips(context, {'router_id': router_ids})
 
-    def get_sync_gw_ports(self, context, gw_port_ids):
+    def _get_sync_gw_ports(self, context, gw_port_ids):
         if not gw_port_ids:
             return []
         filters = {'id': gw_port_ids}
         gw_ports = self._core_plugin.get_ports(context, filters)
-        if gw_ports:
-            self._populate_subnets_for_ports(context, gw_ports)
         return gw_ports
 
-    def get_sync_interfaces(self, context, router_ids, device_owners=None):
+    def _get_sync_interfaces(self, context, router_ids, device_owners=None):
         """Query router interfaces that relate to list of router_ids."""
         device_owners = device_owners or [DEVICE_OWNER_ROUTER_INTF]
         if not router_ids:
@@ -1155,8 +1153,6 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
 
         interfaces = [self._core_plugin._make_port_dict(rp.port, None)
                       for rp in qry]
-        if interfaces:
-            self._populate_subnets_for_ports(context, interfaces)
         return interfaces
 
     def _populate_subnets_for_ports(self, context, ports):
@@ -1238,7 +1234,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
                                              router_ids=router_ids,
                                              active=active)
             router_ids = [router['id'] for router in routers]
-            interfaces = self.get_sync_interfaces(
+            interfaces = self._get_sync_interfaces(
                 context, router_ids, device_owners)
             floating_ips = self._get_sync_floating_ips(context, router_ids)
             return (routers, interfaces, floating_ips)
@@ -1246,6 +1242,9 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
     def get_sync_data(self, context, router_ids=None, active=None):
         routers, interfaces, floating_ips = self._get_router_info_list(
             context, router_ids=router_ids, active=active)
+        ports_to_populate = [router['gw_port'] for router in routers
+                             if router.get('gw_port')] + interfaces
+        self._populate_subnets_for_ports(context, ports_to_populate)
         routers_dict = dict((router['id'], router) for router in routers)
         self._process_floating_ips(context, routers_dict, floating_ips)
         self._process_interfaces(routers_dict, interfaces)
index c8d8356014b5e4b64805705b86dc692ba858bd72..2374361a569f1927d968bcec07fa2a74d1671da8 100644 (file)
@@ -362,8 +362,6 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         interfaces = [self._core_plugin._make_port_dict(rp.port, None)
                       for rp in qry]
         LOG.debug("Return the SNAT ports: %s", interfaces)
-        if interfaces:
-            self._populate_subnets_for_ports(context, interfaces)
         return interfaces
 
     def _build_routers_list(self, context, routers, gw_ports):
@@ -436,8 +434,6 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                    'device_owner': [DEVICE_OWNER_AGENT_GW]}
         interfaces = self._core_plugin.get_ports(context.elevated(), filters)
         LOG.debug("Return the FIP ports: %s ", interfaces)
-        if interfaces:
-            self._populate_subnets_for_ports(context, interfaces)
         return interfaces
 
     def get_dvr_sync_data(self, context, host, agent, router_ids=None,
@@ -457,6 +453,14 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         routers_dict = self._process_routers(context, routers)
         self._process_floating_ips_dvr(context, routers_dict,
                                        floating_ips, host, agent)
+        ports_to_populate = []
+        for router in routers_dict.values():
+            if router.get('gw_port'):
+                ports_to_populate.append(router['gw_port'])
+            if router.get(l3_const.FLOATINGIP_AGENT_INTF_KEY):
+                ports_to_populate += router[l3_const.FLOATINGIP_AGENT_INTF_KEY]
+        ports_to_populate += interfaces
+        self._populate_subnets_for_ports(context, ports_to_populate)
         self._process_interfaces(routers_dict, interfaces)
         return routers_dict.values()