summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-07-05 12:36:22 +0000
committerGerrit Code Review <review@openstack.org>2017-07-05 12:36:22 +0000
commitd88f0f4c84f2c120dcbde2df8c7066d334a1eda6 (patch)
tree50c9d7a343b70deed31a9f9173b5c02b0766018c
parente6274bdd5b36f7b114e255c258659223ba921773 (diff)
parentc94b2a39b3bc484eff6a9c3c9dc094bbfae070c4 (diff)
downloadtooz-d88f0f4c84f2c120dcbde2df8c7066d334a1eda6.tar.gz
Merge "etcd3: replace custom lock code by more recent etcd3 lock code"
-rw-r--r--setup.cfg2
-rw-r--r--tooz/drivers/etcd3.py59
2 files changed, 15 insertions, 46 deletions
diff --git a/setup.cfg b/setup.cfg
index c0d311e..5abaa57 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -45,7 +45,7 @@ consul =
etcd =
requests>=2.10.0 # Apache-2.0
etcd3 =
- etcd3>=0.5.1 # Apache-2.0
+ etcd3>=0.6.2 # Apache-2.0
etcd3gw =
etcd3gw>=0.1.0 # Apache-2.0
zake =
diff --git a/tooz/drivers/etcd3.py b/tooz/drivers/etcd3.py
index 8a747bd..8740b22 100644
--- a/tooz/drivers/etcd3.py
+++ b/tooz/drivers/etcd3.py
@@ -13,7 +13,6 @@
# under the License.
from __future__ import absolute_import
-import uuid
import etcd3
from etcd3 import exceptions as etcd3_exc
@@ -21,7 +20,6 @@ from oslo_utils import encodeutils
import six
import tooz
-from tooz import _retry
from tooz import coordination
from tooz import locking
from tooz import utils
@@ -61,67 +59,38 @@ class Etcd3Lock(locking.Lock):
def __init__(self, coord, name, timeout):
super(Etcd3Lock, self).__init__(name)
- self._timeout = timeout
self._coord = coord
- self._key = self.LOCK_PREFIX + name
- self._uuid = uuid.uuid4().bytes
- self._lease = self._coord.client.lease(self._timeout)
+ self._lock = coord.client.lock(name.decode(), timeout)
@_translate_failures
def acquire(self, blocking=True, shared=False):
if shared:
raise tooz.NotImplemented
- @_retry.retry(stop_max_delay=blocking)
- def _acquire():
- # TODO(jd): save the created revision so we can check it later to
- # make sure we still have the lock
- success, _ = self._coord.client.transaction(
- compare=[
- self._coord.client.transactions.create(self._key) == 0
- ],
- success=[
- self._coord.client.transactions.put(self._key, self._uuid,
- lease=self._lease)
- ],
- failure=[
- self._coord.client.transactions.get(self._key)
- ],
- )
- if success is not True:
- if blocking is False:
- return False
- raise _retry.TryAgain
+ blocking, timeout = utils.convert_blocking(blocking)
+ if blocking is False:
+ timeout = 0
+
+ if self._lock.acquire(timeout):
self._coord._acquired_locks.add(self)
return True
- return _acquire()
+ return False
+
+ @property
+ def acquired(self):
+ return self in self._coord._acquired_locks
@_translate_failures
def release(self):
- success, _ = self._coord.client.transaction(
- compare=[
- self._coord.client.transactions.value(self._key) == self._uuid
- ],
- success=[self._coord.client.transactions.delete(self._key)],
- failure=[],
- )
- if success:
- self._coord._acquired_locks.remove(self)
+ if self.acquired and self._lock.release():
+ self._coord._acquired_locks.discard(self)
return True
return False
@_translate_failures
- def break_(self):
- # FIXME(jd) when pyetcd3 returns the status
- # https://github.com/kragniz/python-etcd3/pull/126
- self._coord.client.delete(self._key)
- self._coord._acquired_locks.discard(self)
- return True
-
- @_translate_failures
def heartbeat(self):
- self._lease.refresh()
+ self._lock.refresh()
class Etcd3Driver(coordination.CoordinationDriver):