From db817a9e39dbed10383cb2c70c0f95d4b1795aec Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Tue, 5 Apr 2016 23:06:00 -0700 Subject: [PATCH] Add semaphore to ML2 create_port db operation This adds a semaphore scoped to the network ID of a port creation in ML2 to ensure that all workers on a single server only try to allocate an IP for that network one at a time. This will alleviate the deadlock error retry mechanism being exceeded due to the related bug. It reduces the number of contenders for a single IP allocation from number of workers to number of servers. It will unblock the switch to pluggable ipam while the IP allocation strategy is being revamped to be less racey. Partial-Bug: #1543094 Change-Id: Ieafdd640777d4654fcd0ebb65ace25c30151c412 --- neutron/plugins/ml2/plugin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 7aff02d3585..59eb69d794b 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -14,6 +14,7 @@ # under the License. from eventlet import greenthread +from oslo_concurrency import lockutils from oslo_config import cfg from oslo_db import api as oslo_db_api from oslo_db import exception as os_db_exception @@ -1088,7 +1089,11 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, return result, mech_context def create_port(self, context, port): - result, mech_context = self._create_port_db(context, port) + # TODO(kevinbenton): remove when bug/1543094 is fixed. + with lockutils.lock(port['port']['network_id'], + lock_file_prefix='neutron-create-port', + external=True): + result, mech_context = self._create_port_db(context, port) # notify any plugin that is interested in port create events kwargs = {'context': context, 'port': result} registry.notify(resources.PORT, events.AFTER_CREATE, self, **kwargs)