diff --git a/src/charm.py b/src/charm.py index a9822fd06e..1789310523 100755 --- a/src/charm.py +++ b/src/charm.py @@ -588,9 +588,10 @@ def _on_peer_relation_changed(self, event: HookEvent) -> None: # noqa: C901 or int(self._patroni.member_replication_lag) > 1000 ) ): + logger.warning("Workload failure detected. Reinitialising unit.") + self.unit.status = MaintenanceStatus("reinitialising replica") self._patroni.reinitialize_postgresql() logger.debug("Deferring on_peer_relation_changed: reinitialising replica") - self.unit.status = MaintenanceStatus("reinitialising replica") event.defer() return @@ -1543,9 +1544,9 @@ def _handle_processes_failures(self) -> bool: and not self._patroni.member_streaming ): try: - self._patroni.reinitialize_postgresql() - logger.info("restarted the replica because it was not streaming from primary") + logger.warning("Degraded member detected: reinitialising unit") self.unit.status = MaintenanceStatus("reinitialising replica") + self._patroni.reinitialize_postgresql() except RetryError: logger.error( "failed to reinitialise replica after checking that it was not streaming from primary" diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 5ad1f11914..cf5783b54c 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -1578,9 +1578,7 @@ def test_handle_processes_failures(harness): harness.charm.unit.status = ActiveStatus() result = harness.charm._handle_processes_failures() assert result == (values[0] is None) - assert isinstance( - harness.charm.unit.status, MaintenanceStatus if values[0] is None else ActiveStatus - ) + assert isinstance(harness.charm.unit.status, MaintenanceStatus) _restart.assert_not_called() _reinitialize_postgresql.assert_called_once()