From 42f1e3ff8ee772df70e26a1360dfccac42e01c99 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 8 May 2020 15:42:53 +0000 Subject: [PATCH] Remove unneeded DB register retrieval and refresh in network update The first DB operation done during a network update is a network DB register retrieval. This information is stored in memory during the DB transaction context and it's updated with any change done to the DB register and the relationships; e.g., the network DB model field "qos_policy_binding" is a backref relationship with a "qos_network_policy_bindings" DB register. When a "qos_network_policy_bindings" register is created, updated or deleted, the network DB object, holding the relationship, will be updated too. There is no need therefore to retrieve again the DB object and force a session update. The DB object contains the updated information. Trivial-Fix Change-Id: I0c10b824c0f919607bb6ea31c5533ce7bd65df42 (cherry picked from commit 0e8ebf133d8fa9a6aee576e265cec64a140b7ded) --- neutron/plugins/ml2/plugin.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index b937e129b14..5c4a7cbee7b 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1080,7 +1080,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, need_network_update_notify = False with db_api.CONTEXT_WRITER.using(context): - original_network = self.get_network(context, id) + db_network = self._get_network(context, id) + original_network = self.get_network(context, id, net_db=db_network) self._update_provider_network_attributes( context, original_network, net_data) @@ -1091,12 +1092,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, updated_network) self._process_l3_update(context, updated_network, net_data) - # ToDO(QoS): This would change once EngineFacade moves out - db_network = self._get_network(context, id) - # Expire the db_network in current transaction, so that the join - # relationship can be updated. - context.session.expire(db_network) - if mtuw_apidef.MTU in net_data: db_network.mtu = self._get_network_mtu(db_network) # agents should now update all ports to reflect new MTU @@ -1138,10 +1133,9 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, return updated_network @db_api.retry_if_session_inactive() - def get_network(self, context, id, fields=None): + def get_network(self, context, id, fields=None, net_db=None): with db_api.CONTEXT_READER.using(context): - net_db = self._get_network(context, id) - + net_db = net_db or self._get_network(context, id) net_data = self._make_network_dict(net_db, context=context) self.type_manager.extend_network_dict_provider(context, net_data)