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.
This commit is contained in:
Oleksii Kliukin
2016-08-29 15:04:50 +02:00
parent 62f14dfd10
commit a9a70d44e2
+3
View File
@@ -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()