Fix in_recovery check (#2773)

The primary that is still alive wasn't properly recognized.
Regression was introduced in #2652
This commit is contained in:
Alexander Kukushkin
2023-07-25 11:50:40 +02:00
committed by GitHub
parent 0e19e3e98e
commit ae2bbd28ae
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ class _MemberStatus(NamedTuple):
# If one of those is not in a response we want to count the node as not healthy/reachable
wal: Dict[str, Any] = json.get('wal') or json['xlog']
# abuse difference in primary/replica response format
in_recovery = not bool(wal.get('location')) or json.get('role') in ('master', 'primary')
in_recovery = not (bool(wal.get('location')) or json.get('role') in ('master', 'primary'))
timeline = json.get('timeline', 0)
dcs_last_seen = json.get('dcs_last_seen', 0)
lsn = int(in_recovery and max(wal.get('received_location', 0), wal.get('replayed_location', 0)))
+4 -1
View File
@@ -885,7 +885,10 @@ class TestHa(PostgresInit):
member = Member(0, 'test', 1, {'api_url': 'http://127.0.0.1:8011/patroni'})
self.ha.fetch_node_status(member)
member = Member(0, 'test', 1, {'api_url': 'http://localhost:8011/patroni'})
self.ha.fetch_node_status(member)
self.ha.patroni.request = Mock()
self.ha.patroni.request.return_value.data = b'{"wal":{"location":1},"role":"primary"}'
ret = self.ha.fetch_node_status(member)
self.assertFalse(ret.in_recovery)
@patch.object(Rewind, 'pg_rewind', true)
@patch.object(Rewind, 'check_leader_is_not_in_recovery', true)