Make RedisLock's init consistent with other locks

Right now RedisLock's __init__ method is not calling its super  __init__
method, as it should be doing.

It's also using attribute named "_acquired" instead of "acquired" and
creating a property name instead of using inherited name attribute  like
other methods are.

This patch changes these behaviors to be consistent with other locks.

Change-Id: If642522637c653a1fb9ad345570fe8a53930cd53
This commit is contained in:
Gorka Eguileor 2015-07-17 13:02:21 +02:00
parent 6bfd6ed7ec
commit 6b1f477996
1 changed files with 10 additions and 13 deletions

View File

@ -56,16 +56,13 @@ def _translate_failures():
class RedisLock(locking.Lock):
def __init__(self, coord, client, name, timeout):
self._name = "%s_%s_lock" % (coord.namespace, six.text_type(name))
self._lock = redis_locks.LuaLock(client, self._name,
name = "%s_%s_lock" % (coord.namespace, six.text_type(name))
super(RedisLock, self).__init__(name)
self._lock = redis_locks.LuaLock(client, name,
timeout=timeout,
thread_local=False)
self._coord = coord
self._acquired = False
@property
def name(self):
return self._name
self.acquired = False
def acquire(self, blocking=True):
if blocking is True or blocking is False:
@ -74,14 +71,14 @@ class RedisLock(locking.Lock):
blocking_timeout = float(blocking)
blocking = True
with _translate_failures():
self._acquired = self._lock.acquire(
self.acquired = self._lock.acquire(
blocking=blocking, blocking_timeout=blocking_timeout)
if self._acquired:
if self.acquired:
self._coord._acquired_locks.add(self)
return self._acquired
return self.acquired
def release(self):
if not self._acquired:
if not self.acquired:
return False
with _translate_failures():
try:
@ -89,11 +86,11 @@ class RedisLock(locking.Lock):
except exceptions.LockError:
return False
self._coord._acquired_locks.discard(self)
self._acquired = False
self.acquired = False
return True
def heartbeat(self):
if self._acquired:
if self.acquired:
with _translate_failures():
self._lock.extend(self._lock.timeout)