Don't rediscover etcd cluster topology when watch timed out (#630)

but switch to the next node if it is possible.

Fixes https://github.com/zalando/patroni/issues/628
This commit is contained in:
Alexander Kukushkin
2018-02-26 18:48:30 +01:00
committed by GitHub
parent c95dd990cc
commit 89a11fed07
2 changed files with 6 additions and 2 deletions
+5 -2
View File
@@ -210,8 +210,11 @@ class Client(etcd.Client):
self._machines_cache = self.machines
if self._base_uri in self._machines_cache:
self._machines_cache.remove(self._base_uri)
except etcd.EtcdConnectionFailed:
self._update_machines_cache = True
except etcd.EtcdConnectionFailed as e:
if isinstance(e, etcd.EtcdWatchTimedOut) and self._machines_cache:
self._base_uri = self._next_server()
else:
self._update_machines_cache = True
if not response:
raise
return self._handle_server_response(response)
+1
View File
@@ -207,6 +207,7 @@ class TestClient(unittest.TestCase):
mock_machines.__get__ = Mock(return_value=['http://localhost:2379'])
self.client._machines_cache_updated = 0
self.client.api_execute('/', 'POST', timeout=0)
self.client._machines_cache = [self.client._base_uri]
self.assertRaises(etcd.EtcdWatchTimedOut, self.client.api_execute, '/timeout', 'POST', params={'wait': 'true'})
self.assertRaises(etcd.EtcdException, self.client.api_execute, '/', '')
self.client._update_machines_cache = True