mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-01-27 18:20:05 +00:00
Don't try calling a non existing leader in patronictl pause (#1542)
While pausing a cluster without a leader on K8s patronictl was showing warnings that member "None" could not be accessed.
This commit is contained in:
committed by
GitHub
parent
fe23d1f2d0
commit
703a129646
@@ -942,7 +942,7 @@ def toggle_pause(config, cluster_name, paused, wait):
|
||||
raise PatroniCtlException('Cluster is {0} paused'.format(paused and 'already' or 'not'))
|
||||
|
||||
members = []
|
||||
if cluster.leader:
|
||||
if cluster.leader and cluster.leader.member.api_url:
|
||||
members.append(cluster.leader.member)
|
||||
members.extend([m for m in cluster.members if m.api_url and (not members or members[0].name != m.name)])
|
||||
|
||||
@@ -1008,7 +1008,7 @@ def show_diff(before_editing, after_editing):
|
||||
If the output is to a tty the diff will be colored. Inputs are expected to be unicode strings.
|
||||
"""
|
||||
def listify(string):
|
||||
return [l+'\n' for l in string.rstrip('\n').split('\n')]
|
||||
return [line + '\n' for line in string.rstrip('\n').split('\n')]
|
||||
|
||||
unified_diff = difflib.unified_diff(listify(before_editing), listify(after_editing))
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ class Ha(object):
|
||||
if cluster_history:
|
||||
self.dcs.set_history_value('[]')
|
||||
elif not cluster_history or cluster_history[-1][0] != master_timeline - 1 or len(cluster_history[-1]) != 4:
|
||||
cluster_history = {l[0]: l for l in cluster_history or []}
|
||||
cluster_history = {line[0]: line for line in cluster_history or []}
|
||||
history = self.state_handler.get_history(master_timeline)
|
||||
if history:
|
||||
history = history[-self.cluster.config.max_timelines_history:]
|
||||
|
||||
@@ -655,7 +655,6 @@ class Postgresql(object):
|
||||
|
||||
def controldata(self):
|
||||
""" return the contents of pg_controldata, or non-True value if pg_controldata call failed """
|
||||
result = {}
|
||||
# Don't try to call pg_controldata during backup restore
|
||||
if self._version_file_exists() and self.state != 'creating replica':
|
||||
try:
|
||||
@@ -663,13 +662,12 @@ class Postgresql(object):
|
||||
env.update(LANG='C', LC_ALL='C')
|
||||
data = subprocess.check_output([self.pgcommand('pg_controldata'), self._data_dir], env=env)
|
||||
if data:
|
||||
data = data.decode('utf-8').splitlines()
|
||||
data = filter(lambda e: ':' in e, data.decode('utf-8').splitlines())
|
||||
# pg_controldata output depends on major version. Some of parameters are prefixed by 'Current '
|
||||
result = {l.split(':')[0].replace('Current ', '', 1): l.split(':', 1)[1].strip() for l in data
|
||||
if l and ':' in l}
|
||||
return {k.replace('Current ', '', 1): v.strip() for k, v in map(lambda e: e.split(':', 1), data)}
|
||||
except subprocess.CalledProcessError:
|
||||
logger.exception("Error when calling pg_controldata")
|
||||
return result
|
||||
return {}
|
||||
|
||||
@contextmanager
|
||||
def get_replication_connection_cursor(self, host='localhost', port=5432, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user