Add limit to Patroni switchover attempts
This commit is contained in:
parent
33a963c2af
commit
7e77752ce5
|
@ -291,6 +291,7 @@ class NodeInstance(object):
|
||||||
|
|
||||||
# Switch Patroni leader to the local instance
|
# Switch Patroni leader to the local instance
|
||||||
self.logger.out('Setting Patroni leader to this node', state='i')
|
self.logger.out('Setting Patroni leader to this node', state='i')
|
||||||
|
tick = 1
|
||||||
while True:
|
while True:
|
||||||
retcode, stdout, stderr = common.run_os_command(
|
retcode, stdout, stderr = common.run_os_command(
|
||||||
"""
|
"""
|
||||||
|
@ -309,8 +310,12 @@ class NodeInstance(object):
|
||||||
elif stderr == "Error: Switchover target and source are the same.\n":
|
elif stderr == "Error: Switchover target and source are the same.\n":
|
||||||
self.logger.out('Failed to switch Patroni leader to ourselves; this is fine\n{}'.format(stderr), state='w')
|
self.logger.out('Failed to switch Patroni leader to ourselves; this is fine\n{}'.format(stderr), state='w')
|
||||||
break
|
break
|
||||||
|
elif tick >= 5:
|
||||||
|
self.logger.out('Failed to switch Patroni leader after 5 tries; aborting\n{}'.format(stderr), state='e')
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
self.logger.out('Failed to switch Patroni leader; retrying\n{}'.format(stderr), state='e')
|
self.logger.out('Failed to switch Patroni leader; retrying [{}/5]\n{}'.format(tick, stderr), state='e')
|
||||||
|
tick += 1
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
# Start the DNS aggregator instance
|
# Start the DNS aggregator instance
|
||||||
|
|
Loading…
Reference in New Issue