From a9a70d44e2e138c6e4667ca575f289da59371f46 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Mon, 29 Aug 2016 15:04:50 +0200 Subject: [PATCH] Make the cached role coherrent with the actual one. When observing the leader running a master role, set the cached role stored in the state_handler to master as well. Failure to do so resulted in the manually promoted node to continue running with a cached 'replica' role. This led to the failure to create replication slots for the new replicas. We could do it conditionally, but both reading and writing the role require the same lock, and the unconditional approach makes the unit tests simpler. --- patroni/ha.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/patroni/ha.py b/patroni/ha.py index 75be52a9..c85afa42 100644 --- a/patroni/ha.py +++ b/patroni/ha.py @@ -158,6 +158,9 @@ class Ha(object): def enforce_master_role(self, message, promote_message): if self.state_handler.is_leader() or self.state_handler.role == 'master': + # Inform the state handler about its master role. + # It may be unaware of it if postgres is promoted manually. + self.state_handler.set_role('master') return message else: self.state_handler.promote()