]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove SELECT FOR UPDATE use in update_firewall
authorCedric Brandily <zzelle@gmail.com>
Tue, 26 Aug 2014 20:57:30 +0000 (22:57 +0200)
committerCedric Brandily <zzelle@gmail.com>
Wed, 27 Aug 2014 09:29:24 +0000 (11:29 +0200)
SELECT FOR UPDATE expression, which is triggered with the use of the
SQLAlchemy Query object's with_lockmode('update') method, is
detrimental to performance and scalability of the database
performance code in Neutron due to the lock contention it produces.

SELECT FOR UPDATE can be entirely avoided in update_firewall method
with the use of single-shot UPDATE expressions.

Change-Id: I333f726498192295116ca96ff5ca9012c36a6fd1

neutron/db/firewall/firewall_db.py

index 3460ea01be86b75c71bf5059cf52a97ae23fa9ab..3ed69e676cfdbbced42c156ff1503f06bb3a4e5a 100644 (file)
@@ -255,11 +255,10 @@ class Firewall_db_mixin(firewall.FirewallPluginBase, base_db.CommonDbMixin):
         LOG.debug(_("update_firewall() called"))
         fw = firewall['firewall']
         with context.session.begin(subtransactions=True):
-            fw_query = context.session.query(
-                Firewall).with_lockmode('update')
-            firewall_db = fw_query.filter_by(id=id).one()
-            firewall_db.update(fw)
-        return self._make_firewall_dict(firewall_db)
+            count = context.session.query(Firewall).filter_by(id=id).update(fw)
+            if not count:
+                raise firewall.FirewallNotFound(firewall_id=id)
+        return self.get_firewall(context, id)
 
     def delete_firewall(self, context, id):
         LOG.debug(_("delete_firewall() called"))