canonical / data-platform-libs

A collection of charm libraries curated by the Data Platform Team
https://charmhub.io/data-platform-libs
Apache License 2.0
9 stars 7 forks source link

[DPE-4598] Handle upgrade of top of the stack Juju leader #176

Closed marceloneppel closed 4 weeks ago

marceloneppel commented 1 month ago

Issue:

The PostgreSQL VM charm rollback test started to fail by the combination of adding TimescaleDB to the Charmed PostgreSQL Snap + updating the upgrade library to LIBPATCH 16 (which removed a defer call that was hiding the issue fixed by this PR).

Explanation of the issue (considering the tests from the PostgreSQL VM charm):

For Kafka and MySQL operators on VM, it hasn’t happened because both always set the upgrade stack with the Juju leader unit as the last unit to be upgraded. For the following codes, remember that the build_upgrade_stack is always executed in the Juju leader unit.

Solution

If the Juju leader unit is the top unit of upgrading the stack, execute the on_upgrade_changed handler logic during a rollback. This way, it can run the logic that starts the upgrade process, in the end of the on_upgrade_changed handler.

This fix was tested on the following charms to avoid breaking them: