Skip to content

Fix logical replication loop#1193

Draft
marceloneppel wants to merge 14 commits into16/edgefrom
fix-logical-replication-loop
Draft

Fix logical replication loop#1193
marceloneppel wants to merge 14 commits into16/edgefrom
fix-logical-replication-loop

Conversation

@marceloneppel
Copy link
Member

Issue

Solution

Checklist

  • I have added or updated any relevant documentation.
  • I have cleaned any remaining cloud resources from my accounts.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…pers

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…ation-loop

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…ation-loop

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…n tests & secret handling

- Add _validate_single_table to validate subscription table format, existence,
  emptiness and detect cyclic logical-replication (reject subscriptions where
  publisher upstream equals subscriber). Improve validation flow to call this
  helper for each requested table.
- Use postgresql.table_exists and postgresql.is_table_empty for accurate checks.
- Improve logging messages and formatting during upstream determination and
  configured-time comparison.
- Fix configured-time comparison code formatting and simplify generator usage.
- Remove unused requester_id variable.
- In offer propagation, allow direct propagation to offers via
  _propagate_upstream_to_offers(mapping, set_configured_time=False) (used in
  tests) instead of relying on full rebuild that may overwrite manual mappings.
- Tests (unit + integration):
  - Patch charm.postgresql property via PropertyMock to return a DB mock and
    mock DB operations (create_user, create_publication, grant/revoke, delete_user,
    drop_publication) to avoid real DB connections.
  - Mock logical_replication._create_user and charm.update_config to avoid
    database/K8s API access.
  - Create model secret in harness and set secret-id in app relation data to
    simulate provided credentials (no external secret store needed).
  - Adjust test data formatting and minor style cleanups.
- Misc: small formatting / logging string normalization for readability.

This change improves validation safety (prevents cycles and invalid table
subscriptions), and makes tests hermetic by fully mocking external DB/K8s
dependencies.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…ation-loop

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
This reverts commit 8d51bc2.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…ed key

Expose logical_replication_subscription_request in the Pydantic config (Field(default=None)) and update test to use the hyphenated "logical-replication-subscription-request" key.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
@marceloneppel marceloneppel added the bug Something isn't working as expected label Dec 19, 2025
@github-actions github-actions bot added the Libraries: Out of sync The charm libs used are out-of-sync label Dec 19, 2025
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

❌ Patch coverage is 55.83756% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.10%. Comparing base (877f814) to head (331ac87).

Files with missing lines Patch % Lines
src/relations/logical_replication.py 57.22% 61 Missing and 16 partials ⚠️
src/backups.py 28.57% 4 Missing and 1 partial ⚠️
src/charm.py 44.44% 3 Missing and 2 partials ⚠️

❌ Your project check has failed because the head coverage (67.10%) is below the target coverage (70.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           16/edge    #1193      +/-   ##
===========================================
- Coverage    68.93%   67.10%   -1.83%     
===========================================
  Files           17       18       +1     
  Lines         3850     4332     +482     
  Branches       577      657      +80     
===========================================
+ Hits          2654     2907     +253     
- Misses         990     1176     +186     
- Partials       206      249      +43     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ation-loop

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…ance tracking

Add per-table upstream provenance to detect replication cycles and correctly
identify origin nodes. Nodes now report themselves as origin for tables they
don't subscribe to, enabling accurate cycle detection in multi-hop chains.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…ation-loop

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected Libraries: Out of sync The charm libs used are out-of-sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant