diff --git a/src/backups.py b/src/backups.py index 217c17b8aa..58eeac0fc5 100644 --- a/src/backups.py +++ b/src/backups.py @@ -219,6 +219,11 @@ def _is_s3_wal_compatible(self, stanza) -> Tuple[bool, Optional[str]]: and charm_last_archived_wal.split(".", 1)[0] != str(s3_last_archived_wal) ): if bool(self.charm.app_peer_data.get("require-change-bucket-after-restore", None)): + self.charm.app_peer_data.update({ + "restoring-backup": "", + "restore-stanza": "", + "restore-to-time": "", + }) return False, MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET else: return False, ANOTHER_CLUSTER_REPOSITORY_ERROR_MESSAGE @@ -594,12 +599,13 @@ def _on_s3_credential_changed(self, event: CredentialsChangedEvent): event.defer() return + if self.charm.unit.is_leader(): + self.charm.app_peer_data.pop("require-change-bucket-after-restore", None) + # Verify the s3 relation only on the primary. if not self.charm.is_primary: return - self.charm.app_peer_data.pop("require-change-bucket-after-restore", None) - try: self._create_bucket_if_not_exists() except (ClientError, ValueError): diff --git a/src/charm.py b/src/charm.py index 362b0931e0..05d8729bb4 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1410,12 +1410,13 @@ def _set_primary_status_message(self) -> None: """Display 'Primary' in the unit status message if the current unit is the primary.""" try: if "require-change-bucket-after-restore" in self.app_peer_data: + if self.charm.unit.is_leader(): + self.app_peer_data.update({ + "restoring-backup": "", + "restore-stanza": "", + "restore-to-time": "", + }) self.unit.status = BlockedStatus(MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET) - self.app_peer_data.update({ - "restoring-backup": "", - "restore-stanza": "", - "restore-to-time": "", - }) return if self._patroni.get_primary(unit_name_pattern=True) == self.unit.name: self.unit.status = ActiveStatus("Primary")