Implement more checks in the follow method

Although such situation should not happen in reality (follow method is
not supposed to be called when when the node is holding leader lock and
postgres is running), but to be on the safe side it is better to
implement as much checks as possible, because this method could
potentially remove data directory.
This commit is contained in:
Alexander Kukushkin
2016-07-04 10:56:37 +02:00
parent ee529669d2
commit b84e22c4ea
2 changed files with 8 additions and 2 deletions
+6 -2
View File
@@ -730,8 +730,12 @@ class Postgresql(object):
change_role = self.role == 'master'
self._need_rewind = (not leader or leader.name != self.name) \
and (self._need_rewind or change_role and self.can_rewind)
if leader and leader.name == self.name:
self._need_rewind = False
if self.is_running():
return
else:
self._need_rewind = self._need_rewind or change_role and self.can_rewind
if self._need_rewind:
logger.info("set the rewind flag after demote")
+2
View File
@@ -257,6 +257,8 @@ class TestPostgresql(unittest.TestCase):
with patch.object(Postgresql, 'check_recovery_conf', Mock(return_value=True)):
self.assertTrue(self.p.follow(None, None)) # nothing to do, recovery.conf has good primary_conninfo
self.p.follow(self.me, self.me) # follow is called when the node is holding leader lock
with patch.object(Postgresql, 'restart', Mock(return_value=False)):
self.p.set_role('replica')
self.p.follow(None, None) # restart without rewind