Skip to content

Commit 4212050

Browse files
author
avandras
committed
Remove 'replicating' message from patronictl list, fix None issues
1 parent 02c64db commit 4212050

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

patroni/ctl.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,9 @@ def get_cluster_service_info(cluster: Dict[str, Any]) -> List[str]:
17431743
if 'multisite' in cluster:
17441744
info = f"Multisite {cluster['multisite'].get('name') or ''} is {cluster['multisite']['status'].lower()}"
17451745
standby_config = cluster['multisite'].get('standby_config', {})
1746-
if standby_config and standby_config.get('host'):
1746+
replicating_states = ['streaming', 'in archive recovery']
1747+
leader = [m for m in cluster.get('members', []) if m['role'] == 'Standby Leader'][0]
1748+
if standby_config and standby_config.get('host') and leader and leader['state'] in replicating_states:
17471749
info += f", replicating from {standby_config['leader_site']}"
17481750
info += f" ({standby_config['host']}:{standby_config.get('port', 5432)})"
17491751
service_info.append(info)
@@ -1753,12 +1755,13 @@ def get_cluster_service_info(cluster: Dict[str, Any]) -> List[str]:
17531755
if 'members' in cluster:
17541756
r = reduce(ior, cluster['members'], {})
17551757
if 'latest_end_lsn' in r:
1756-
lag_to_primary = r['lag_to_primary']
1758+
lag_to_primary = r.get('lag_to_primary')
17571759
lag_to_primary = round(lag_to_primary / 1024 / 1024) if isinstance(lag_to_primary, int) \
17581760
else '' if lag_to_primary == 'unknown' else lag_to_primary
1759-
info = (f"The latest known LSN of the primary instance is {r['latest_end_lsn']}, "
1760-
f"the replication lag is {lag_to_primary} MB")
1761-
service_info.append(info)
1761+
if r['latest_end_lsn'] and lag_to_primary:
1762+
info = (f"The latest known LSN of the primary instance is {r['latest_end_lsn']}, "
1763+
f"the replication lag is {lag_to_primary} MB")
1764+
service_info.append(info)
17621765

17631766
if cluster.get('pause'):
17641767
service_info.append('Maintenance mode: on')

patroni/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ def cluster_as_json(cluster: 'Cluster') -> Dict[str, Any]:
997997
member[lsn_type] = format_lsn(lsn)
998998
elif m.name == leader_name and (config.is_standby_cluster or multisite_active):
999999
latest_end_lsn = getattr(m, 'latest_end_lsn')
1000-
member['latest_end_lsn'] = format_lsn(latest_end_lsn)
1000+
member['latest_end_lsn'] = format_lsn(latest_end_lsn) if latest_end_lsn else ''
10011001
if member['latest_end_lsn']:
10021002
member['lag_to_primary'] = latest_end_lsn - cluster_lsn
10031003

0 commit comments

Comments
 (0)