Skip to content

Conversation

marceloneppel
Copy link
Member

@marceloneppel marceloneppel commented Jan 31, 2024

Issue

The stanza can only be initialised in the PostgreSQL primary unit if it's the Juju leader unit.

Otherwise, the unit fails with an error, as shown in canonical/postgresql-k8s-operator#370.

Solution

Ported from canonical/postgresql-k8s-operator#375.

Allow the non-leader unit (when it's the PostgreSQL primary) to initialise the stanza.

For that, all checks for the unit being the Juju leader unit were changed to check whether the unit is the PostgreSQL primary.

Also, some coordination is now made in the relation databags to share the stanza name and the init-pgbackrest flag.

The current flow doesn't change if the PostgreSQL primary unit is also the Juju leader unit.

If they are different units, then:

  • The stanza name and the init-pgbackres flag are set in the primary unit relation databag.
  • The leader unit copies those values to the application relation databag (to be used later for other actions in backups).
  • The pgbackrest check command is executed in the primary unit, which clears the init-pgbackrest flag from the unit relation databag.
  • The leader unit clears the init-pgbackrest flag from the application relation databag.
  • The primary unit clears the stanza name from the unit relation databag.

Both unit and integration tests were added/updated to ensure we keep this flow intact.

Also, the fix from canonical/postgresql-k8s-operator#273 was added through this PR, as it was not applied to the VM charm.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
@marceloneppel marceloneppel changed the title [DPE=3380] Handle S3 relation in primary non-leader unit [DPE-3380] Handle S3 relation in primary non-leader unit Feb 1, 2024
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (acc0d26) 80.00% compared to head (548fbde) 80.05%.

❗ Current head 548fbde differs from pull request most recent head 641562e. Consider uploading reports for the commit 641562e to get more accurate results

Files Patch % Lines
src/charm.py 16.66% 4 Missing and 1 partial ⚠️
src/backups.py 96.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #340      +/-   ##
==========================================
+ Coverage   80.00%   80.05%   +0.04%     
==========================================
  Files          10       10              
  Lines        2176     2206      +30     
  Branches      344      354      +10     
==========================================
+ Hits         1741     1766      +25     
- Misses        368      371       +3     
- Partials       67       69       +2     

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

…tanza-on-primary

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>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
@marceloneppel marceloneppel marked this pull request as ready for review February 9, 2024 02:23
Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@marceloneppel marceloneppel merged commit a87c52b into main Feb 9, 2024
@marceloneppel marceloneppel deleted the dpe-3380-initialise-stanza-on-primary branch February 9, 2024 11:46
BON4 pushed a commit to BON4/postgresql-operator that referenced this pull request Apr 23, 2024
* Handle S3 relation in primary non-leader unit

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

* Fix replication after restore

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

* Fix unit name

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

* Speed up events

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

* Change fast_interval parameter

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

---------

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants