MDB-43767: consider db in crash recovery state as db in non-terminal state#132
Merged
Conversation
Collaborator
Race conditionRace condition in _rewind_from_source(): pg_rewind may start before PostgreSQL fully stops In _rewind_from_source() Suggested FixRemove def _rewind_from_source(self, limit, new_primary): # removed is_postgresql_dead
logging.info("Starting pg_rewind")
# Wait for source database to be available
if not helpers.await_for(
lambda: not self._check_host_is_really_dead(new_primary),
limit,
'source database alive and ready for rewind',
):
return None
# Mark destructive operation in ZK
if not self.zk.write('%s/%s/op' % (self.zk.MEMBERS_PATH, helpers.get_hostname()), 'rewind', need_lock=False):
logging.error('Unable to save destructive op state: rewind')
return None
self.db.pgpooler('stop')
# Always ensure PostgreSQL is stopped before rewind
if self.db.get_postgresql_status() == 0: # if process is running
if self.stop_postgresql(timeout=limit) != 0:
logging.error('Could not stop PostgreSQL. Will retry.')
return None
# Wait for PostgreSQL to fully stop
if not helpers.await_for(
lambda: self.db.get_postgresql_status() != 0,
limit,
'PostgreSQL fully stopped'
):
logging.error('PostgreSQL did not stop in time. Will retry.')
return None
self.checks['rewind'] += 1
if self.db.do_rewind(new_primary) != 0:
logging.error('Error while using pg_rewind. Will retry.')
return True
# Rewind has finished successfully so we can drop its operation node
self.zk.delete('%s/%s/op' % (self.zk.MEMBERS_PATH, helpers.get_hostname()))
return self._attach_to_primary(new_primary, limit) |
Collaborator
Added here: #138 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.