mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Rename sleep to watch in a AbstractDCS
This method suppose to watch for changes of leader key if current node is not leader and also it could watch for changes in a members list if current conde is the leader.
This commit is contained in:
+1
-1
@@ -153,5 +153,5 @@ class AbstractDCS:
|
||||
"""Voluntarily remove leader key from DCS
|
||||
This method should remove leader key if current instance is the leader"""
|
||||
|
||||
def sleep(self, timeout):
|
||||
def watch(self, timeout):
|
||||
sleep(timeout)
|
||||
|
||||
+2
-2
@@ -224,7 +224,7 @@ class Etcd(AbstractDCS):
|
||||
def delete_leader(self):
|
||||
return self.client.delete(self.client_path('/leader'), prevValue=self._name)
|
||||
|
||||
def sleep(self, timeout):
|
||||
def watch(self, timeout):
|
||||
# watch on leader key changes if it is defined and current node is not lock owner
|
||||
if self.cluster and self.cluster.leader and self.cluster.leader.member.name != self._name:
|
||||
end_time = time.time() + timeout
|
||||
@@ -244,4 +244,4 @@ class Etcd(AbstractDCS):
|
||||
|
||||
timeout = end_time - time.time()
|
||||
|
||||
timeout > 0 and super(Etcd, self).sleep(timeout)
|
||||
timeout > 0 and super(Etcd, self).watch(timeout)
|
||||
|
||||
@@ -220,7 +220,7 @@ class ZooKeeper(AbstractDCS):
|
||||
if isinstance(self.leader, Leader) and self.leader.member.name == self._name:
|
||||
self.client.delete(self.client_path('/leader'))
|
||||
|
||||
def sleep(self, timeout):
|
||||
def watch(self, timeout):
|
||||
self.cluster_event.wait(timeout)
|
||||
if self.cluster_event.isSet():
|
||||
self.fetch_cluster = True
|
||||
|
||||
+6
-6
@@ -253,11 +253,11 @@ class TestEtcd(unittest.TestCase):
|
||||
self.etcd.client.delete = etcd_delete
|
||||
self.assertFalse(self.etcd.delete_leader())
|
||||
|
||||
def test_sleep(self):
|
||||
def test_watch(self):
|
||||
self.etcd.client.watch = etcd_watch
|
||||
self.etcd.sleep(100)
|
||||
self.etcd.watch(100)
|
||||
self.etcd.get_cluster()
|
||||
self.etcd.sleep(1)
|
||||
self.etcd.sleep(5)
|
||||
self.etcd.sleep(10)
|
||||
self.etcd.sleep(100)
|
||||
self.etcd.watch(1)
|
||||
self.etcd.watch(5)
|
||||
self.etcd.watch(10)
|
||||
self.etcd.watch(100)
|
||||
|
||||
@@ -164,5 +164,5 @@ class TestZooKeeper(unittest.TestCase):
|
||||
self.zk.last_leader_operation = -1
|
||||
self.assertTrue(self.zk.update_leader(MockPostgresql()))
|
||||
|
||||
def test_sleep(self):
|
||||
self.zk.sleep(0)
|
||||
def test_watch(self):
|
||||
self.zk.watch(0)
|
||||
|
||||
Reference in New Issue
Block a user