]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Randomize tunnel id query to avoid contention
authorEugene Nikanorov <enikanorov@mirantis.com>
Sun, 10 May 2015 21:34:35 +0000 (01:34 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Sun, 10 May 2015 22:18:54 +0000 (02:18 +0400)
When networks are created rapidly, neutron-servers compete
for segmentation ids which creates too much contention and
may lead to inability to choose available id in hardcoded amount
of attempts (11)
Randomize tunnel id selection so that condition is not hit.

Change-Id: I7068f90fe4927e6e693f8a62cb704213b2da2920
Related-Bug: #1382064
Closes-Bug: #1454434

neutron/plugins/ml2/drivers/helpers.py

index 2404947d5203e079acb327066249d58339c11710..1e8b1fca01b3db70b409cc50cdd16e9e44726cd3 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import random
+
 from oslo_config import cfg
 from oslo_db import exception as db_exc
 from oslo_log import log
@@ -24,6 +26,8 @@ from neutron.plugins.ml2 import driver_api as api
 
 LOG = log.getLogger(__name__)
 
+IDPOOL_SELECT_SIZE = 100
+
 
 class BaseTypeDriver(api.TypeDriver):
     """BaseTypeDriver for functions common to Segment and flat."""
@@ -121,12 +125,13 @@ class SegmentTypeDriver(BaseTypeDriver):
                       filter_by(allocated=False, **filters))
 
             # Selected segment can be allocated before update by someone else,
-            alloc = select.first()
+            allocs = select.limit(IDPOOL_SELECT_SIZE).all()
 
-            if not alloc:
+            if not allocs:
                 # No resource available
                 return
 
+            alloc = random.choice(allocs)
             raw_segment = dict((k, alloc[k]) for k in self.primary_keys)
             LOG.debug("%(type)s segment allocate from pool "
                       "started with %(segment)s ",