diff options
author | Zuul <zuul@review.opendev.org> | 2020-03-04 03:02:16 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-03-04 03:02:16 +0000 |
commit | 6e7a8508fbcbe9ceacb04490dc8330501bfa2477 (patch) | |
tree | f9f356c94d3e84cecf352ac3defebde11c0769c4 | |
parent | 27c4f158e5571c20069fc72d0b40a303da8149b2 (diff) | |
parent | 6e750b6921c42f3c2ffed2e135be4d9c65e96f36 (diff) | |
download | tooz-6e7a8508fbcbe9ceacb04490dc8330501bfa2477.tar.gz |
Merge "Adds heartbeating to the consul driver."2.2.0
-rw-r--r-- | releasenotes/notes/consul-heartbeat-support-3ec69e2ace537dc1.yaml | 9 | ||||
-rw-r--r-- | tooz/drivers/consul.py | 13 |
2 files changed, 22 insertions, 0 deletions
diff --git a/releasenotes/notes/consul-heartbeat-support-3ec69e2ace537dc1.yaml b/releasenotes/notes/consul-heartbeat-support-3ec69e2ace537dc1.yaml new file mode 100644 index 0000000..7aa8dd4 --- /dev/null +++ b/releasenotes/notes/consul-heartbeat-support-3ec69e2ace537dc1.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + Added heartbeat supported to the Consul driver so that locks would remain locked + instead of timing out on the first TTL. This can be considered both a feature and + a bug fix because previously the Consul driver would only hold the lock for the + first TTL and behind the scenes Consul would release it due to the lack of session + updates. In order for the Consul driver to perform distributed locking properly + you MUST utilize heartbeats! diff --git a/tooz/drivers/consul.py b/tooz/drivers/consul.py index f5cfd9b..26a72e0 100644 --- a/tooz/drivers/consul.py +++ b/tooz/drivers/consul.py @@ -158,6 +158,19 @@ class ConsulDriver(coordination.CoordinationDriver): self._session_id = None self._client = None + def heartbeat(self): + # THIS IS A REQUIREMENT FOR CONSUL TO WORK PROPERLY. + # Consul maintains a "session" token that is used to as the basis + # for all operations in the service. The session must be refreshed + # periodically or else it assumes that the agent maintaining the + # session has died or is unreachable. When a session expires all locks + # are released and any services that were registered with that session + # are marked as no longer active. + self._client.session.renew(self._session_id) + # renew the session every half-TTL or 1 second, whatever is larger + sleep_sec = max(self._ttl / 2, 1) + return sleep_sec + def get_lock(self, name): real_name = self._paths_join(self._namespace, u"locks", name) return ConsulLock(real_name, self._node, self._address, |