From e8fd77445bd81f837c36733e8adc0019e59bd5c6 Mon Sep 17 00:00:00 2001 From: Furtchet Date: Tue, 10 Oct 2017 12:47:56 -0500 Subject: [PATCH] Allow failover to one node --- bin/manage.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/manage.py b/bin/manage.py index 3a68239..cf5e567 100644 --- a/bin/manage.py +++ b/bin/manage.py @@ -21,6 +21,8 @@ PRIMARY, REPLICA, UNASSIGNED, \ UnknownPrimary, WaitTimeoutError +from manager.discovery import FAILOVER_KEY + class Node(object): """ @@ -84,6 +86,13 @@ def is_primary(self): self.cp.state = PRIMARY return True + # A fail over is happening and I'm the only one left and I got the lock + _, failover_name = self.consul.read_lock(FAILOVER_KEY) + log.debug('failover_name: %s' % failover_name) + if failover_name == self.name: + self.cp.state = PRIMARY + return True + self.cp.state = UNASSIGNED return False