Skip to content

Commit 5b08579

Browse files
Stabilisation...
1 parent 3381fb3 commit 5b08579

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/charm.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,6 @@ def _peer_relation_changed_checks(self, event: HookEvent) -> bool:
862862
"""Split of to reduce complexity."""
863863
# Prevents the cluster to be reconfigured before it's bootstrapped in the leader.
864864
logger.debug(f"Calling on_peer_relation_changed, event: '{event}'")
865-
if hasattr(event, "unit") and event.unit is None:
866-
logger.debug(f"Early exit on_peer_relation_changed: event to itself ({event.unit})")
867-
return False
868865

869866
if not self.is_cluster_initialised:
870867
logger.debug("Early exit on_peer_relation_changed: cluster not initialized")
@@ -883,7 +880,9 @@ def _peer_relation_changed_checks(self, event: HookEvent) -> bool:
883880

884881
# Don't update this member before it's part of the members list.
885882
if self._unit_ip not in self.members_ips:
886-
logger.debug("Early exit on_peer_relation_changed: Unit not in the members list")
883+
logger.debug(
884+
"Early exit on_peer_relation_changed: Unit not in the members list {self.members_ips}"
885+
)
887886
return False
888887
return True
889888

@@ -2357,7 +2356,7 @@ def update_config(
23572356
parameters=pg_parameters,
23582357
no_peers=no_peers,
23592358
user_databases_map=self.relations_user_databases_map,
2360-
slots=replication_slots or None,
2359+
slots=replication_slots,
23612360
)
23622361
if no_peers:
23632362
logger.debug("Early exit update_config: no peers")

src/cluster.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from contextlib import suppress
1616
from pathlib import Path
1717
from ssl import CERT_NONE, create_default_context
18+
from time import sleep
1819
from typing import TYPE_CHECKING, Any, TypedDict
1920

2021
import charm_refresh
@@ -442,6 +443,10 @@ def get_patroni_health(self) -> dict[str, str]:
442443

443444
def is_restart_pending(self) -> bool:
444445
"""Returns whether the Patroni/PostgreSQL restart pending."""
446+
# The current Patroni 3.2.2 has wired behaviour: it temporary flag pending_restart=True
447+
# on any changes to REST API, which is gone within a second but long enough to be
448+
# cougth by charm. Sleep 2 seconds as a protection here until Patroni 3.3.0 upgrade
449+
sleep(2)
445450
r = requests.get(
446451
f"{self._patroni_url}/patroni",
447452
verify=self.verify,

templates/patroni.yml.j2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,13 @@ bootstrap:
101101
set_user.block_log_statement: 'on'
102102
set_user.exit_on_error: 'on'
103103
set_user.superuser_allowlist: '+charmed_dba'
104-
{%- if slots %}
105104
slots:
106105
{%- for slot, database in slots.items() %}
107106
{{slot}}:
108107
database: {{database}}
109108
plugin: pgoutput
110109
type: logical
111110
{%- endfor -%}
112-
{% endif %}
113111

114112
{%- if restoring_backup %}
115113
method: pgbackrest

tests/unit/test_charm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ class _MockSnap:
11631163
parameters={"test": "test"},
11641164
no_peers=False,
11651165
user_databases_map={"operator": "all", "replication": "all", "rewind": "all"},
1166-
slots=None,
1166+
slots={},
11671167
)
11681168
_handle_postgresql_restart_need.assert_called_once_with()
11691169
_restart_ldap_sync_service.assert_called_once()
@@ -1194,7 +1194,7 @@ class _MockSnap:
11941194
parameters={"test": "test"},
11951195
no_peers=False,
11961196
user_databases_map={"operator": "all", "replication": "all", "rewind": "all"},
1197-
slots=None,
1197+
slots={},
11981198
)
11991199
_handle_postgresql_restart_need.assert_called_once()
12001200
_restart_ldap_sync_service.assert_called_once()

0 commit comments

Comments
 (0)