]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move away nested transaction from _ensure_default_security_group
authorRoey Chen <roeyc@vmware.com>
Wed, 29 Jul 2015 11:45:29 +0000 (04:45 -0700)
committerRoey Chen <roeyc@vmware.com>
Sun, 2 Aug 2015 13:53:48 +0000 (13:53 +0000)
This patch remove the nested transaction started in
_ensure_default_security_group, before calling create_security_group.
Instead, a nested transaction will be started inside
create_security_group.

The purpose of this change is to reduce the time period in which the db
transaction is open (to avoid races, db lock timeouts, etc), when creating
the default security-group.

Closes-Bug: #1479558
Change-Id: Ia0efa72c70c2f405c851370b0b26770008e5ff95

neutron/db/securitygroups_db.py

index 49b4f0913c4f87d86bfff8f6007cd9f5130740fa..c769beba4e1e2b01ef83bd1aa2544e03621edbe8 100644 (file)
@@ -151,7 +151,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
         if not default_sg:
             self._ensure_default_security_group(context, tenant_id)
 
-        with context.session.begin(subtransactions=True):
+        with db_api.autonested_transaction(context.session):
             security_group_db = SecurityGroup(id=s.get('id') or (
                                               uuidutils.generate_uuid()),
                                               description=s['description'],
@@ -663,9 +663,8 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
                          'description': _('Default security group')}
                 }
                 try:
-                    with db_api.autonested_transaction(context.session):
-                        ret = self.create_security_group(
-                            context, security_group, default_sg=True)
+                    ret = self.create_security_group(
+                        context, security_group, default_sg=True)
                 except exception.DBDuplicateEntry as ex:
                     LOG.debug("Duplicate default security group %s was "
                               "not created", ex.value)