From fd8b88ef542197f85e42cfe721d3d5217905acc8 Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Fri, 9 Apr 2021 15:27:23 +0300 Subject: [PATCH] Do a quick FIP check on port delete Get FloatingIP object results in a quite heavy DB request. On port delete it's in fact done 2 times: lines 1628 and 1635 in current patch's l3_db.py (please see diff). A simple and quick check at the beginning significantly improves performance for deleting ports not associated with floating IPs, which seems the most common case. Also add the check to _get_floatingips_by_port_id() to improve performance of create and update ports not associated with floating IPs. For associated ports the overhead should be negligible. Change-Id: Iab3e242b297f8484c120c8999155abd908cf6d6e --- neutron/db/l3_db.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index e89f9fa885e..1c058c9f32c 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -1621,6 +1621,10 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, @return: set of router-ids that require notification updates """ with db_api.CONTEXT_WRITER.using(context): + if not l3_obj.FloatingIP.objects_exist( + context, fixed_port_id=port_id): + return [] + floating_ip_objs = l3_obj.FloatingIP.get_objects( context, fixed_port_id=port_id) router_ids = {fip.router_id for fip in floating_ip_objs} @@ -1665,7 +1669,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, def _get_floatingips_by_port_id(self, context, port_id): """Helper function to retrieve the fips associated with a port_id.""" - return l3_obj.FloatingIP.get_objects(context, fixed_port_id=port_id) + if l3_obj.FloatingIP.objects_exist(context, fixed_port_id=port_id): + return l3_obj.FloatingIP.get_objects( + context, fixed_port_id=port_id) + else: + return [] def _build_routers_list(self, context, routers, gw_ports): """Subclasses can override this to add extra gateway info"""