summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-09-18 08:36:09 +0000
committerGerrit Code Review <review@openstack.org>2014-09-18 08:36:09 +0000
commita07fe43b3d608de6df102d37a3b1fab0b0f93fa0 (patch)
treead990346156d279685da2ce62bf65853732900e5
parent3139512c9f29836a7e61669c8fcac24d45898b44 (diff)
parent12ecba2b73b78458d45020085bd5e8851e94e11b (diff)
downloadtooz-a07fe43b3d608de6df102d37a3b1fab0b0f93fa0.tar.gz
Merge "Standardize on the same lock acquire method definition"
-rw-r--r--tooz/drivers/ipc.py4
-rw-r--r--tooz/drivers/zookeeper.py19
-rw-r--r--tooz/locking.py2
3 files changed, 18 insertions, 7 deletions
diff --git a/tooz/drivers/ipc.py b/tooz/drivers/ipc.py
index ba2302c..c754958 100644
--- a/tooz/drivers/ipc.py
+++ b/tooz/drivers/ipc.py
@@ -112,9 +112,7 @@ class IPCDriver(coordination.CoordinationDriver):
:param lock_timeout: how many seconds to wait when trying to acquire
a lock in blocking mode. None means forever, 0
means don't wait, any other value means wait
- this amount of seconds. super(IPCDriver,
- self).__init__() self.lock_timeout =
- lock_timeout
+ this amount of seconds.
"""
super(IPCDriver, self).__init__()
self.lock_timeout = int(options.get('lock_timeout', ['30'])[-1])
diff --git a/tooz/drivers/zookeeper.py b/tooz/drivers/zookeeper.py
index 5585743..07cf0d2 100644
--- a/tooz/drivers/zookeeper.py
+++ b/tooz/drivers/zookeeper.py
@@ -27,11 +27,13 @@ from tooz import locking
class ZooKeeperLock(locking.Lock):
- def __init__(self, name, lock):
+ def __init__(self, name, lock, timeout):
super(ZooKeeperLock, self).__init__(name)
self._lock = lock
+ self.timeout = timeout
- def acquire(self, blocking=True, timeout=None):
+ def acquire(self, blocking=True):
+ timeout = self.timeout if blocking else None
return self._lock.acquire(blocking=blocking,
timeout=timeout)
@@ -40,6 +42,15 @@ class ZooKeeperLock(locking.Lock):
class BaseZooKeeperDriver(coordination.CoordinationDriver):
+ """Initialize the IPC driver.
+
+ :param timeout: connection timeout to wait when first connecting to the
+ zookeeper server
+ :param lock_timeout: how many seconds to wait when trying to acquire
+ a lock in blocking mode. None means forever, 0
+ means don't wait, any other value means wait
+ this amount of seconds.
+ """
_TOOZ_NAMESPACE = b"tooz"
@@ -47,6 +58,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
super(BaseZooKeeperDriver, self).__init__()
self._member_id = member_id
self.timeout = int(options.get('timeout', ['10'])[-1])
+ self.lock_timeout = int(options.get('lock_timeout', ['30'])[-1])
def start(self):
try:
@@ -334,7 +346,8 @@ class KazooDriver(BaseZooKeeperDriver):
name,
self._coord.Lock(
self.paths_join(b"/", self._TOOZ_NAMESPACE, b"locks", name),
- self._member_id.decode('ascii')))
+ self._member_id.decode('ascii')),
+ self.lock_timeout)
def run_watchers(self):
ret = []
diff --git a/tooz/locking.py b/tooz/locking.py
index 43b43f7..b12912e 100644
--- a/tooz/locking.py
+++ b/tooz/locking.py
@@ -44,7 +44,7 @@ class Lock(object):
"""
@abc.abstractmethod
- def acquire(self):
+ def acquire(self, blocking=True):
"""Attempts to acquire the lock.
:returns: returns true if acquired (false if not)