Skip to content

Commit

Permalink
Standby cluster can't have synchronous nodes (patroni#3079)
Browse files Browse the repository at this point in the history
`synchronous_standby_names` and synchronous replication only work on a real primary node and in case of cascading replication simply ignored by Postgres.
This fact was already addressed by `global_config.is_synchronous_mode`, but in case if in a standby cluster the `/sync` key in DCS is not empty, `patronictl list` and `GET /cluster` were falsely reporting some nodes as synchronous because this check was missing.

Close patroni#3078
  • Loading branch information
CyberDem0n authored Jun 14, 2024
1 parent 14a44e1 commit af03c61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion patroni/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ def cluster_as_json(cluster: 'Cluster') -> Dict[str, Any]:
for m in cluster.members:
if m.name == leader_name:
role = 'standby_leader' if config.is_standby_cluster else 'leader'
elif cluster.sync.matches(m.name):
elif config.is_synchronous_mode and cluster.sync.matches(m.name):
role = 'sync_standby'
else:
role = 'replica'
Expand Down
8 changes: 8 additions & 0 deletions tests/test_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,14 @@ def test_list_extended(self):
assert '2100' in result.output
assert 'Scheduled restart' in result.output

def test_list_standby_cluster(self):
cluster = get_cluster_initialized_without_leader(leader=True, sync=('leader', 'other'))
cluster.config.data.update(synchronous_mode=True, standby_cluster={'port': 5433})
with patch('patroni.dcs.AbstractDCS.get_cluster', Mock(return_value=cluster)):
result = self.runner.invoke(ctl, ['list'])
self.assertEqual(result.exit_code, 0)
self.assertNotIn('Sync Standby', result.output)

def test_topology(self):
cluster = get_cluster_initialized_with_leader()
cluster.members.append(Member(0, 'cascade', 28,
Expand Down

0 comments on commit af03c61

Please sign in to comment.