Skip to content
Merged
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
6 changes: 5 additions & 1 deletion lib/charms/postgresql_k8s/v0/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class PostgreSQLEnableDisableExtensionError(Exception):
"""Exception raised when enabling/disabling an extension fails."""


class PostgreSQLGetLastArchivedWALError(Exception):
"""Exception raised when retrieving last archived WAL fails."""


class PostgreSQLGetPostgreSQLVersionError(Exception):
"""Exception raised when retrieving PostgreSQL version fails."""

Expand Down Expand Up @@ -391,7 +395,7 @@ def get_last_archived_wal(self) -> str:
return cursor.fetchone()[0]
except psycopg2.Error as e:
logger.error(f"Failed to get PostgreSQL last archived WAL: {e}")
raise PostgreSQLGetPostgreSQLVersionError()
raise PostgreSQLGetLastArchivedWALError()

def get_postgresql_text_search_configs(self) -> Set[str]:
"""Returns the PostgreSQL available text search configs.
Expand Down
5 changes: 3 additions & 2 deletions src/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,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
6 changes: 6 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,12 @@ 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.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)
return
if self._patroni.get_primary(unit_name_pattern=True) == self.unit.name:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ async def test_restore_on_new_cluster(ops_test: OpsTest, github_secrets, charm)
async with ops_test.fast_forward():
unit = ops_test.model.units.get(f"{database_app_name}/0")
await ops_test.model.block_until(
lambda: unit.workload_status_message == ANOTHER_CLUSTER_REPOSITORY_ERROR_MESSAGE
lambda: unit.workload_status_message == MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET
)

# Check that the backup was correctly restored by having only the first created table.
Expand Down