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
(cherry picked from commit db817a9e39)
This commit is contained in:
Kevin Benton 2016-04-05 23:06:00 -07:00 committed by stephen-ma
parent 0c4218202c
commit c871a43383
1 changed files with 6 additions and 1 deletions

View File

@ -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)