Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MISC] Improve TLS stability #685

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,12 @@ def update_config(self, is_creating_backup: bool = False) -> bool:
return True

if not self._patroni.member_started:
if enable_tls:
logger.debug(
"Early exit update_config: patroni not responding but TLS is enabled."
)
self._handle_postgresql_restart_need(True)
return True
logger.debug("Early exit update_config: Patroni not started yet")
return False

Expand Down Expand Up @@ -1780,8 +1786,14 @@ def _validate_config_options(self) -> None:

def _handle_postgresql_restart_need(self, enable_tls: bool) -> None:
"""Handle PostgreSQL restart need based on the TLS configuration and configuration changes."""
restart_postgresql = self.is_tls_enabled != self.postgresql.is_tls_enabled()
self._patroni.reload_patroni_configuration()
if self._can_connect_to_postgresql:
restart_postgresql = self.is_tls_enabled != self.postgresql.is_tls_enabled()
else:
restart_postgresql = False
try:
self._patroni.reload_patroni_configuration()
except Exception as e:
logger.error(f"Reload patroni call failed! error: {e!s}")
# Wait for some more time than the Patroni's loop_wait default value (10 seconds),
# which tells how much time Patroni will wait before checking the configuration
# file again to reload it.
Expand Down
2 changes: 1 addition & 1 deletion src/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def remove_raft_member(self, member_ip: str) -> None:
if not result.startswith("SUCCESS"):
raise RemoveRaftMemberFailedError()

@retry(stop=stop_after_attempt(10), wait=wait_exponential(multiplier=1, min=2, max=10))
@retry(stop=stop_after_attempt(20), wait=wait_exponential(multiplier=1, min=2, max=10))
def reload_patroni_configuration(self):
"""Reload Patroni configuration after it was changed."""
requests.post(
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ def test_update_config(harness):
harness.update_relation_data(
rel_id, harness.charm.unit.name, {"tls": ""}
) # Mock some data in the relation to test that it doesn't change.
_is_tls_enabled.return_value = False
harness.charm.update_config()
_handle_postgresql_restart_need.assert_not_called()
assert "tls" not in harness.get_relation_data(rel_id, harness.charm.unit.name)
Expand Down
Loading