Skip to content

Commit

Permalink
Refactor config access to remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
thedodd committed Aug 1, 2022
1 parent 0420532 commit 66c69a4
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions patroni/ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def is_paused(self):
def check_timeline(self):
return self.check_mode('check_timeline')

def get_static_primary_config(self):
if self.cluster and self.cluster.config and self.cluster.config.modify_index:
config = self.cluster.config.data
else:
config = self.patroni.config.dynamic_configuration
return config.get('static_primary')

def get_standby_cluster_config(self):
if self.cluster and self.cluster.config and self.cluster.config.modify_index:
config = self.cluster.config.data
Expand All @@ -130,23 +137,15 @@ def is_leader(self):

def is_static_primary(self):
"""Check if this node is configured as the static primary of the cluster."""
if self.cluster and self.cluster.config and self.cluster.config.modify_index:
config = self.cluster.config.data
else:
config = self.patroni.config.dynamic_configuration
static_primary = config.get('static_primary')
name = self.state_handler.name
static_primary = self.get_static_primary_config()
if static_primary is None or name is None:
return False
return static_primary == name

def is_static_primary_configured(self):
"""Check if the Patroni cluster has been configured with a static primary."""
if self.cluster and self.cluster.config and self.cluster.config.modify_index:
config = self.cluster.config.data
else:
config = self.patroni.config.dynamic_configuration
return config.get('static_primary') is not None
return self.get_static_primary_config() is not None

def set_is_leader(self, value):
with self._is_leader_lock:
Expand Down

0 comments on commit 66c69a4

Please sign in to comment.