Skip to content

Commit

Permalink
Treat Postgres shutdown notification as a clear sign of failover
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Sep 9, 2021
1 parent 4edf727 commit 42c74af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions edb/server/pgcon/pgcon.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ cdef class PGConnection:
msg = fields.get('M', msg)
if self.is_system_db:
self.server.set_pg_unavailable_msg(msg)
self.server._on_sys_pgcon_failover_signal()
continue
raise RuntimeError(
f'unexpected message type {chr(mtype)!r} in IDLE state')
Expand Down
25 changes: 15 additions & 10 deletions edb/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,16 +920,21 @@ def _on_sys_pgcon_connection_lost(self, exc):

def _on_sys_pgcon_parameter_status_updated(self, name, value):
if name == 'in_hot_standby' and value == 'on':
if self._backend_passive_ha:
# It is a strong evidence of failover if the sys_pgcon receives
# a notification that in_hot_standby is turned on.
self._backend_passive_ha.set_state_failover()
elif getattr(self._cluster, '_ha_backend', None) is None:
# If the server is not using an HA backend, nor has enabled the
# passive HA monitoring, we still tries to "switch over" by
# disconnecting all pgcons if in_hot_standby is turned on.
self.on_switch_over()
# Else, the HA backend should take care of calling on_switch_over()
# It is a strong evidence of failover if the sys_pgcon receives
# a notification that in_hot_standby is turned on.
self._on_sys_pgcon_failover_signal()

def _on_sys_pgcon_failover_signal(self):
if self._backend_passive_ha is not None:
# Switch to FAILOVER if passive HA is enabled
self._backend_passive_ha.set_state_failover()
elif getattr(self._cluster, '_ha_backend', None) is None:
# If the server is not using an HA backend, nor has enabled the
# passive HA monitoring, we still tries to "switch over" by
# disconnecting all pgcons if failover signal is received, allowing
# reconnection to happen sooner.
self.on_switch_over()
# Else, the HA backend should take care of calling on_switch_over()

def _on_pgcon_broken(self, is_sys_pgcon=False):
if self._backend_passive_ha:
Expand Down

0 comments on commit 42c74af

Please sign in to comment.