diff options
| author | Mark Washenberger <mark.washenberger@rackspace.com> | 2012-02-02 11:38:25 -0500 |
|---|---|---|
| committer | Mark Washenberger <mark.washenberger@rackspace.com> | 2012-02-02 11:41:12 -0500 |
| commit | df4c59e22b1a8a67b418d36e7c0404b110bfd3f8 (patch) | |
| tree | 32f50e26244a1fe39945cb49a75f749a3ab906f4 | |
| parent | e58e492020f2bbd1cf54226b630b9f1e9571df69 (diff) | |
| download | nova-df4c59e22b1a8a67b418d36e7c0404b110bfd3f8.tar.gz nova-df4c59e22b1a8a67b418d36e7c0404b110bfd3f8.tar.xz nova-df4c59e22b1a8a67b418d36e7c0404b110bfd3f8.zip | |
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
| -rw-r--r-- | nova/utils.py | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/nova/utils.py b/nova/utils.py index 0d3067fd3..d1968ac4d 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -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. |
