Don't fire on_reload when promoting to standby_leader on 13+ (#1552)

PostgreSQL 13 finally introduced the possibility to change the `primary_conninfo` without a restart. Just doing reload is enough, but in case if the role is changing from the `replica` to the `standby_leader` we want to call only `on_role_change` callback and skip `on_reload`, because they duplicate each other.
This commit is contained in:
Alexander Kukushkin
2020-06-29 14:49:25 +02:00
committed by GitHub
parent cbff544b9c
commit 8eb01c77b6
2 changed files with 7 additions and 4 deletions
+4 -3
View File
@@ -615,9 +615,9 @@ class Postgresql(object):
except psycopg2.Error:
pass
def reload(self):
def reload(self, block_callbacks=False):
ret = self.pg_ctl('reload')
if ret:
if ret and not block_callbacks:
self.call_nowait(ACTION_ON_RELOAD)
return ret
@@ -777,7 +777,8 @@ class Postgresql(object):
if self.is_running():
if do_reload:
self.config.write_postgresql_conf()
self.reload()
if self.reload(block_callbacks=change_role) and change_role:
self.set_role(role)
else:
self.restart(block_callbacks=change_role, role=role)
else:
+3 -1
View File
@@ -153,7 +153,6 @@ def run_async(self, func, args=()):
@patch.object(Postgresql, 'is_leader', Mock(return_value=True))
@patch.object(Postgresql, 'timeline_wal_position', Mock(return_value=(1, 10, 1)))
@patch.object(Postgresql, '_cluster_info_state_get', Mock(return_value=3))
@patch.object(Postgresql, 'call_nowait', Mock(return_value=True))
@patch.object(Postgresql, 'data_directory_empty', Mock(return_value=False))
@patch.object(Postgresql, 'controldata', Mock(return_value={
'Database system identifier': SYSID,
@@ -705,6 +704,9 @@ class TestHa(PostgresInit):
self.ha._leader_timeline = 1
self.assertEqual(self.ha.run_cycle(), 'promoted self to a standby leader because i had the session lock')
self.assertEqual(self.ha.run_cycle(), 'no action. i am the standby leader with the lock')
self.p.set_role('replica')
self.p.config.check_recovery_conf = Mock(return_value=(True, False))
self.assertEqual(self.ha.run_cycle(), 'promoted self to a standby leader because i had the session lock')
def test_process_healthy_standby_cluster_as_cascade_replica(self):
self.p.is_leader = false