Optionally disable file locking.

File locks in nova have a bad habit of lingering if the process that
created them is killed, and there isn't a good automated way to fix this
behavior. This option allows a deployer to avoid the problem if they
know they are only running a single nova process on a machine.

Change-Id: I1ae20cc54a4614b200093ffd581d3ab21d7c241b
This commit is contained in:
Mark Washenberger 2012-02-02 11:38:25 -05:00
parent 046e74c3d4
commit 43ffe75c59

@ -45,6 +45,7 @@ from eventlet import semaphore
from eventlet.green import subprocess
import netaddr
from nova.common import cfg
from nova import exception
from nova import flags
from nova import log as logging
@ -56,6 +57,11 @@ PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
FLAGS = flags.FLAGS
FLAGS.add_option(
cfg.BoolOpt('disable_process_locking', default=False,
help='Whether to disable inter-process locks'))
def import_class(import_str):
"""Returns a class from a string including module and class."""
mod_str, _sep, class_str = import_str.rpartition('.')
@ -764,14 +770,6 @@ else:
_semaphores = {}
class _NoopContextManager(object):
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
pass
def synchronized(name, external=False):
"""Synchronization decorator.
@ -816,21 +814,19 @@ def synchronized(name, external=False):
LOG.debug(_('Got semaphore "%(lock)s" for method '
'"%(method)s"...' % {'lock': name,
'method': f.__name__}))
if external:
if external and not FLAGS.disable_process_locking:
LOG.debug(_('Attempting to grab file lock "%(lock)s" for '
'method "%(method)s"...' %
{'lock': name, 'method': f.__name__}))
lock_file_path = os.path.join(FLAGS.lock_path,
'nova-%s' % name)
lock = lockfile.FileLock(lock_file_path)
else:
lock = _NoopContextManager()
with lock:
if external:
with lock:
LOG.debug(_('Got file lock "%(lock)s" for '
'method "%(method)s"...' %
{'lock': name, 'method': f.__name__}))
retval = f(*args, **kwargs)
else:
retval = f(*args, **kwargs)
# If no-one else is waiting for it, delete it.