mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Handle DCS exceptions when demoting (#2081)
While doing demote due to failure to update leader lock it could happen that DCS goes completely down and the get_cluster() call raise the exception. Not being properly handled it results in postgres remaining stopped until DCS recovers.
This commit is contained in:
+5
-2
@@ -870,8 +870,11 @@ class Ha(object):
|
||||
if mode_control['offline']:
|
||||
node_to_follow, leader = None, None
|
||||
else:
|
||||
cluster = self.dcs.get_cluster()
|
||||
node_to_follow, leader = self._get_node_to_follow(cluster), cluster.leader
|
||||
try:
|
||||
cluster = self.dcs.get_cluster()
|
||||
node_to_follow, leader = self._get_node_to_follow(cluster), cluster.leader
|
||||
except Exception:
|
||||
node_to_follow, leader = None, None
|
||||
|
||||
# FIXME: with mode offline called from DCS exception handler and handle_long_action_in_progress
|
||||
# there could be an async action already running, calling follow from here will lead
|
||||
|
||||
@@ -402,6 +402,8 @@ class TestHa(PostgresInit):
|
||||
self.ha.has_lock = true
|
||||
self.ha.update_lock = false
|
||||
self.assertEqual(self.ha.run_cycle(), 'demoted self because failed to update leader lock in DCS')
|
||||
with patch.object(Ha, '_get_node_to_follow', Mock(side_effect=DCSError('foo'))):
|
||||
self.assertEqual(self.ha.run_cycle(), 'demoted self because failed to update leader lock in DCS')
|
||||
self.p.is_leader = false
|
||||
self.assertEqual(self.ha.run_cycle(), 'not promoting because failed to update leader lock in DCS')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user