mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
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:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user