Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for postgres to finish starting or stopping in dead iter #54

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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