mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Cancel long-running jobs on Patroni stop (#3232)
Patroni could be doing replica bootstrap and we don't want want pg_basebackup/wal-g/pgBackRest/barman or similar keep running. Besides that, remove data directory on replica bootstrap failure if configuration allows. Close #3224
This commit is contained in:
@@ -2298,6 +2298,7 @@ class Ha(object):
|
|||||||
return 'Unexpected exception raised, please report it as a BUG'
|
return 'Unexpected exception raised, please report it as a BUG'
|
||||||
|
|
||||||
def shutdown(self) -> None:
|
def shutdown(self) -> None:
|
||||||
|
self._async_executor.cancel()
|
||||||
if self.is_paused():
|
if self.is_paused():
|
||||||
logger.info('Leader key is not deleted and Postgresql is not stopped due paused state')
|
logger.info('Leader key is not deleted and Postgresql is not stopped due paused state')
|
||||||
self.watchdog.disable()
|
self.watchdog.disable()
|
||||||
|
|||||||
@@ -318,6 +318,10 @@ class Bootstrap(object):
|
|||||||
logger.exception('Error creating replica using method %s', replica_method)
|
logger.exception('Error creating replica using method %s', replica_method)
|
||||||
ret = 1
|
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')
|
self._postgresql.set_state('stopped')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@@ -359,6 +363,9 @@ class Bootstrap(object):
|
|||||||
if bbfailures < maxfailures - 1:
|
if bbfailures < maxfailures - 1:
|
||||||
logger.warning('Trying again in 5 seconds')
|
logger.warning('Trying again in 5 seconds')
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
elif not self._postgresql.data_directory_empty():
|
||||||
|
# pg_basebackup failed, clean up data directory
|
||||||
|
self._postgresql.remove_data_directory()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user