Skip to content

Commit 105a1f5

Browse files
committed
Patch from the async code
1 parent 0e40971 commit 105a1f5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/relations/async_replication.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,16 @@ def _on_async_relation_changed(self, event: RelationChangedEvent) -> None:
544544
if self._configure_primary_cluster(primary_cluster, event):
545545
return
546546

547+
# Patch API config if following leader.
548+
if (
549+
self.charm.unit.is_leader()
550+
and self._is_following_promoted_cluster()
551+
and (primary_endpoint := self.get_primary_cluster_endpoint())
552+
):
553+
self.charm._patroni.bulk_update_parameters_controller_by_patroni({
554+
"standby_cluster": {"host": primary_endpoint}
555+
})
556+
547557
# Return if this is a new unit.
548558
if not self.charm.unit.is_leader() and self._is_following_promoted_cluster():
549559
logger.debug("Early exit on_async_relation_changed: following promoted cluster.")

tests/integration/high_availability/test_async_replication.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def test_unrelate_and_relate(first_model: str, second_model: str) -> None:
266266
def test_failover_in_main_cluster(first_model: str, second_model: str) -> None:
267267
"""Test that async replication fails over correctly."""
268268
model_1 = Juju(model=first_model)
269+
model_2 = Juju(model=second_model)
269270

270271
rerelate_test_app(model_1, DB_APP_1, DB_TEST_APP_1)
271272

@@ -274,6 +275,9 @@ def test_failover_in_main_cluster(first_model: str, second_model: str) -> None:
274275
model_1.wait(
275276
ready=wait_for_apps_status(jubilant.all_active, DB_APP_1), timeout=10 * MINUTE_SECS
276277
)
278+
model_2.wait(
279+
ready=wait_for_apps_status(jubilant.all_active, DB_APP_2), timeout=10 * MINUTE_SECS
280+
)
277281

278282
results = get_db_max_written_values(first_model, second_model, first_model, DB_TEST_APP_1)
279283

0 commit comments

Comments
 (0)