Skip to content

Commit

Permalink
Don't let replica restore initialize key when DCS was wiped (patroni#…
Browse files Browse the repository at this point in the history
…2970)

It was happening from the branch where Patroni was supposed to be complain about converting standalone PG cluster to be governed by Patroni and exit.
  • Loading branch information
CyberDem0n authored Dec 5, 2023
1 parent 6976939 commit 0e6a2ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 2 additions & 3 deletions patroni/ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -1849,10 +1849,9 @@ def _run_cycle(self) -> str:
logger.fatal('system ID mismatch, node %s belongs to a different cluster: %s != %s',
self.state_handler.name, self.cluster.initialize, data_sysid)
sys.exit(1)
elif self.cluster.is_unlocked() and not self.is_paused():
elif self.cluster.is_unlocked() and not self.is_paused() and not self.state_handler.cb_called:
# "bootstrap", but data directory is not empty
if not self.state_handler.cb_called and self.state_handler.is_running() \
and not self.state_handler.is_primary():
if self.state_handler.is_running() and not self.state_handler.is_primary():
self._join_aborted = True
logger.error('No initialize key in DCS and PostgreSQL is running as replica, aborting start')
logger.error('Please first start Patroni on the node running as primary')
Expand Down
5 changes: 5 additions & 0 deletions tests/test_ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,11 @@ def test_abort_join(self, exit_mock):
self.p.is_primary = false
self.ha.run_cycle()
exit_mock.assert_called_once_with(1)
self.p.set_role('replica')
self.ha.dcs.initialize = Mock()
with patch.object(Postgresql, 'cb_called', PropertyMock(return_value=True)):
self.assertEqual(self.ha.run_cycle(), 'promoted self to leader by acquiring session lock')
self.ha.dcs.initialize.assert_not_called()

@patch.object(Cluster, 'is_unlocked', Mock(return_value=False))
def test_after_pause(self):
Expand Down

0 comments on commit 0e6a2ff

Please sign in to comment.