Skip to content

Commit

Permalink
wait for postgres to finish starting or stopping in dead iter (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
munakoiso authored Nov 20, 2024
1 parent 1725297 commit 1c65e13
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ def run_iteration(self, my_prio):
return
stream_from = self.config.get('global', 'stream_from')
if role is None:
is_dead = terminal_state
self.dead_iter(db_state, zk_state, is_actually_dead=is_dead)
self.dead_iter(db_state, zk_state, is_in_terminal_state=terminal_state)
elif role == 'primary':
if self._is_single_node:
self.single_node_primary_iter(db_state, zk_state)
Expand Down Expand Up @@ -857,7 +856,7 @@ def replica_iter(self, db_state, zk_state):
logging.error(line.rstrip())
return None

def dead_iter(self, db_state, zk_state, is_actually_dead):
def dead_iter(self, db_state, zk_state, is_in_terminal_state):
"""
Iteration if local postgresql is dead
"""
Expand All @@ -878,6 +877,9 @@ def dead_iter(self, db_state, zk_state, is_actually_dead):
holder = self.zk.get_current_lock_holder()
if holder and holder != helpers.get_hostname():
if role == 'replica' and holder == last_primary:
if not is_in_terminal_state:
logging.warning('Waiting for postgres to finish starting or stopping.')
return None
self._acquire_replication_source_slot_lock(last_primary)
logging.info('Seems that primary has not changed but PostgreSQL is dead. Starting it.')
return self.db.start_postgresql()
Expand All @@ -890,7 +892,7 @@ def dead_iter(self, db_state, zk_state, is_actually_dead):
logging.warning(
'Seems that primary is %s and local PostgreSQL is dead. We should return to cluster here.', holder
)
return self._return_to_cluster(holder, role, is_dead=is_actually_dead)
return self._return_to_cluster(holder, role, is_dead=is_in_terminal_state)

else:
#
Expand Down

0 comments on commit 1c65e13

Please sign in to comment.