Skip to content
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
15 changes: 15 additions & 0 deletions single_kernel_postgresql/managers/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
K8S_PGBACK_REST_SERVER_SERVICE_NAME,
K8S_PGBACKREST_METRICS_SERVER_SERVICE_NAME,
K8S_POSTGRESQL_SERVICE_NAME,
LOGICAL_REPLICATION_OFFER_RELATION,
LOGICAL_REPLICATION_RELATION,
ORIGINAL_PATRONI_ON_FAILURE_CONDITION,
REPLICATION_CONSUMER_RELATION,
REPLICATION_OFFER_RELATION,
Expand Down Expand Up @@ -258,6 +260,19 @@ def _pre_restore_cluster_checks(self) -> str:
logger.error(f"Restore failed: {error_message}")
return error_message

logger.info("Checking that cluster does not have an active logical replication relation")
for relation in [
self.state.model.get_relation(LOGICAL_REPLICATION_RELATION),
*self.state.model.relations.get(LOGICAL_REPLICATION_OFFER_RELATION, ()),
]:
if not relation:
continue
error_message = (
"Unit cannot restore backup with an active logical replication relation"
)
logger.error(f"Restore failed: {error_message}")
return error_message

logger.info("Checking that this unit was already elected the leader unit")
if not self.state.peer.is_app_leader:
error_message = "Unit cannot restore backup as it was not elected the leader unit yet"
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_restore_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ def test_pre_restore_checks_rejects_active_async_relation(harness, restore_manag
assert message == "Unit cannot restore backup with an active async replication relation"


@pytest.mark.parametrize(
"endpoint",
["logical-replication", "logical-replication-offer"],
)
def test_pre_restore_checks_rejects_active_logical_replication_relation(
harness, restore_manager, endpoint
):
with harness.hooks_disabled():
harness.add_relation(endpoint, "other-postgresql")
ok, message = restore_manager.pre_restore_checks(BACKUP_ID, None)
assert not ok
assert message == "Unit cannot restore backup with an active logical replication relation"


def test_pre_restore_checks_rejects_non_leader(harness, restore_manager):
with harness.hooks_disabled():
harness.set_leader(False)
Expand Down
Loading