Pause state improvements

This commit is contained in:
Murat Kabilov
2016-08-25 12:01:05 +02:00
parent 4e61ef06a8
commit 5c63c9ffbd
2 changed files with 11 additions and 10 deletions
+10 -8
View File
@@ -535,21 +535,23 @@ class Ha(object):
def pause_action(self): def pause_action(self):
if not self.state_handler.is_healthy(): if not self.state_handler.is_healthy():
return "Postgresql is not running" return "Postgresql is not running. No action due to paused state"
if not (self.state_handler.is_leader() or self.state_handler.role == 'master'): if not self.state_handler.is_leader():
return "I'm secondary" if self.has_lock():
self.dcs.delete_leader()
return "I'm secondary. No action due to paused state"
if self.has_lock(): if self.has_lock():
if not self.update_lock(): if not self.update_lock():
# Either there is no connection to DCS or someone else acquired the lock # Either there is no connection to DCS or someone else acquired the lock
logger.error('failed to update leader lock') logger.error('failed to update leader lock')
self.load_cluster_from_dcs() self.load_cluster_from_dcs()
else: return "I'm the leader. Updating leader key"
elif self.cluster.is_unlocked():
if not self.acquire_lock(): if not self.acquire_lock():
raise Exception("Someone already acquired the lock") return "Can't acquire the lock. No action due to paused state"
return "Cluster has no leader. Acquiring leader key"
return "I'm the leader"
def _run_cycle(self): def _run_cycle(self):
try: try:
@@ -568,7 +570,7 @@ class Ha(object):
return self.handle_long_action_in_progress() return self.handle_long_action_in_progress()
if self.is_paused(): if self.is_paused():
return self.pause_action() + ". No action due to paused state" return self.pause_action()
# we've got here, so any async action has finished. Check if we tried to recover and failed # we've got here, so any async action has finished. Check if we tried to recover and failed
if self.recovering: if self.recovering:
-1
View File
@@ -10,4 +10,3 @@ click>=4.1
prettytable>=0.7 prettytable>=0.7
tzlocal tzlocal
python-dateutil python-dateutil
coverage