From fdd4e276f2f423532073bb8a4ecf3b1f3e99c6de Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Wed, 28 Apr 2021 16:50:47 +0300 Subject: [PATCH] Improve Subnet delete performance - don't re-fetch subnet object from DB - network is not used in SubnetContext when deleting subnet Above gives ~35% improvement Change-Id: I34f850782092f771482a297ae1e68a63ffb027c1 (cherry picked from commit bdd50ffcde2875c877127975294dd5a29213e92b) --- neutron/db/db_base_plugin_v2.py | 3 ++- neutron/plugins/ml2/plugin.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 671da0ea5dd..e05940fa051 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -1056,7 +1056,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, with db_api.exc_to_retry(sql_exc.IntegrityError), \ db_api.CONTEXT_WRITER.using(context): registry.notify(resources.SUBNET, events.PRECOMMIT_DELETE, - self, context=context, subnet_id=subnet.id) + self, context=context, subnet_id=subnet.id, + subnet_obj=subnet) subnet.delete() # Delete related ipam subnet manually, # since there is no FK relationship diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index bf605d858ae..4665bd07d13 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1312,11 +1312,11 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, @registry.receives(resources.SUBNET, [events.PRECOMMIT_DELETE], priority=0) def _subnet_delete_precommit_handler(self, rtype, event, trigger, context, subnet_id, **kwargs): - subnet_obj = self._get_subnet_object(context, subnet_id) + subnet_obj = (kwargs.get('subnet_obj') or + self._get_subnet_object(context, subnet_id)) subnet = self._make_subnet_dict(subnet_obj, context=context) - network = self.get_network(context, subnet['network_id']) mech_context = driver_context.SubnetContext(self, context, - subnet, network) + subnet, network=None) # TODO(kevinbenton): move this mech context into something like # a 'delete context' so it's not polluting the real context object setattr(context, '_mech_context', mech_context)