From 94c52991e00c24e5fad3c29629a4c6b7d182f488 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Thu, 12 Oct 2017 09:21:57 +0200 Subject: [PATCH] Set role to uninitialized if data directory was removed in runtime Fixes https://github.com/zalando/patroni/issues/542 --- patroni/ha.py | 1 + tests/test_ha.py | 1 + 2 files changed, 2 insertions(+) diff --git a/patroni/ha.py b/patroni/ha.py index 43d14a94..730bec56 100644 --- a/patroni/ha.py +++ b/patroni/ha.py @@ -1014,6 +1014,7 @@ class Ha(object): # is data directory empty? if self.state_handler.data_directory_empty(): + self.state_handler.set_role('uninitialized') # In case datadir went away while we were master. TODO: check for this and try to stop postgresql. self.watchdog.disable() diff --git a/tests/test_ha.py b/tests/test_ha.py index 6162ef2c..fa3d0cec 100644 --- a/tests/test_ha.py +++ b/tests/test_ha.py @@ -862,6 +862,7 @@ class TestHa(unittest.TestCase): self.ha.has_lock = true self.p.data_directory_empty = true self.assertEquals(self.ha.run_cycle(), 'released leader key voluntarily as data dir empty and currently leader') + self.assertEquals(self.p.role, 'uninitialized') # as has_lock is mocked out, we need to fake the leader key release self.ha.has_lock = false