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

Syncing from upstream patroni/patroni (bugfix/cancel-async-on-stop) #478

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
13 changes: 9 additions & 4 deletions patroni/postgresql/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,14 @@ def create_replica(self, clone_member: Union[Leader, Member, None]) -> Optional[
else:
logger.error('Error creating replica using method %s: %s exited with code=%s',
replica_method, cmd, ret)
if not method_config.get('keep_data', False):
self._postgresql.remove_data_directory()
except Exception:
logger.exception('Error creating replica using method %s', replica_method)
ret = 1

# replica creation method failed, clean up data directory if configuration allows
if not method_config.get('keep_data', False) and not self._postgresql.data_directory_empty():
self._postgresql.remove_data_directory()

self._postgresql.set_state('stopped')
return ret

Expand All @@ -343,10 +345,10 @@ def basebackup(self, conn_url: str, env: Dict[str, str], options: Dict[str, Any]
] + user_options

for bbfailures in range(0, maxfailures):
if not self._postgresql.data_directory_empty():
self._postgresql.remove_data_directory()
if self._postgresql.cancellable.is_cancelled:
break
if not self._postgresql.data_directory_empty():
self._postgresql.remove_data_directory()
try:
logger.debug('calling: %r', cmd)
ret = self._postgresql.cancellable.call(cmd, env=env)
Expand All @@ -361,6 +363,9 @@ def basebackup(self, conn_url: str, env: Dict[str, str], options: Dict[str, Any]
if bbfailures < maxfailures - 1:
logger.warning('Trying again in 5 seconds')
time.sleep(5)
elif not self._postgresql.data_directory_empty():
# pg_basebackup failed, clean up data directory
self._postgresql.remove_data_directory()

return ret

Expand Down
Loading