Skip to content

Commit

Permalink
Correctly access application peer data
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo Henrique Neppel <[email protected]>
  • Loading branch information
marceloneppel committed Jul 5, 2024
1 parent cd8fdda commit 0a0f45d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 6 additions & 5 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0a0f45d

Please sign in to comment.