summaryrefslogtreecommitdiff
path: root/tooz/drivers/etcd3.py
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2017-06-27 17:39:22 +0200
committerJulien Danjou <julien@danjou.info>2017-06-28 10:56:13 +0200
commit7987f4455a7ff4e75d64c46a42d50017f53bfc9e (patch)
treeaa92e9b65840955d878d812df192a9317565237a /tooz/drivers/etcd3.py
parentc94b2a39b3bc484eff6a9c3c9dc094bbfae070c4 (diff)
downloadtooz-7987f4455a7ff4e75d64c46a42d50017f53bfc9e.tar.gz
Make sure Lock.heartbeat() returns True/False
- add a test to be sure that no lock refresh is made on non-acquired locks - add thread safety for etcd3 drivers on heartbeat() (like Redis) Change-Id: I350ea10163d59a06712c22c4c5be4dfcb6885bf8
Diffstat (limited to 'tooz/drivers/etcd3.py')
-rw-r--r--tooz/drivers/etcd3.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/tooz/drivers/etcd3.py b/tooz/drivers/etcd3.py
index 253f6d1..213711d 100644
--- a/tooz/drivers/etcd3.py
+++ b/tooz/drivers/etcd3.py
@@ -13,6 +13,7 @@
# under the License.
from __future__ import absolute_import
+import threading
import etcd3
from etcd3 import exceptions as etcd3_exc
@@ -61,6 +62,7 @@ class Etcd3Lock(locking.Lock):
super(Etcd3Lock, self).__init__(name)
self._coord = coord
self._lock = coord.client.lock(name.decode(), timeout)
+ self._exclusive_access = threading.Lock()
@_translate_failures
def acquire(self, blocking=True, shared=False):
@@ -83,14 +85,19 @@ class Etcd3Lock(locking.Lock):
@_translate_failures
def release(self):
- if self.acquired and self._lock.release():
- self._coord._acquired_locks.discard(self)
- return True
+ with self._exclusive_access:
+ if self.acquired and self._lock.release():
+ self._coord._acquired_locks.discard(self)
+ return True
return False
@_translate_failures
def heartbeat(self):
- self._lock.refresh()
+ with self._exclusive_access:
+ if self.acquired:
+ self._lock.refresh()
+ return True
+ return False
class Etcd3Driver(coordination.CoordinationDriver):