Use cached role as a fallback when postgres is slow (#2082)

In some extreme cases Postgres could be so slow that the normal monitoring query doesn't finish in a few seconds. It results in
the exception being raised from the `Postgresql._cluster_info_state_get()` method, which could lead to the situation that postgres isn't demoted on time.
In order to make it reliable we will catch the exception and use the cached state of postgres (`is_running()` and `role`) to determine whether postgres is running as a primary.

Close https://github.com/zalando/patroni/issues/2073
This commit is contained in:
Alexander Kukushkin
2021-10-07 16:08:21 +02:00
committed by GitHub
parent 89388c2e4b
commit 250328b84b
2 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -335,7 +335,7 @@ class TestPostgresql(BaseTestPostgresql):
self.assertTrue(self.p.is_leader())
self.p.reset_cluster_info_state(None)
with patch.object(Postgresql, '_query', Mock(side_effect=RetryFailedError(''))):
self.assertRaises(PostgresConnectionException, self.p.is_leader)
self.assertFalse(self.p.is_leader())
@patch.object(Postgresql, 'controldata', Mock(return_value={'Database cluster state': 'shut down',
'Latest checkpoint location': '0/1ADBC18',