Merge "Optionally disable file locking."

This commit is contained in:
Jenkins 2012-02-02 17:31:16 +00:00 committed by Gerrit Code Review
commit af1a92f973

View File

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