Merge ~r00ta/maas:lp-2058273-sync-bootresources-deterministic-3.5 into maas:3.5

Proposed by Jacopo Rota
Status: Merged
Approved by: Jacopo Rota
Approved revision: 6c002aa673f81a8d3e479eaeae23617bbb6107f1
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~r00ta/maas:lp-2058273-sync-bootresources-deterministic-3.5
Merge into: maas:3.5
Diff against target: 44 lines (+8/-3)
1 file modified
src/maasserver/workflow/bootresource.py (+8/-3)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Jacopo Rota Approve
Review via email: mp+462671@code.launchpad.net

Commit message

fix: lp-2058273. Make the sync-bootresources workflow deterministic

(cherry-picked from 37bb6c453c7f0971f551affb939ee6368996c10d)

To post a comment you must log in.
Revision history for this message
Jacopo Rota (r00ta) wrote :

self approving backport

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp-2058273-sync-bootresources-deterministic-3.5 lp:~r00ta/maas/+git/maas into -b 3.5 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 6c002aa673f81a8d3e479eaeae23617bbb6107f1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/workflow/bootresource.py b/src/maasserver/workflow/bootresource.py
2index 4097f7e..513908d 100644
3--- a/src/maasserver/workflow/bootresource.py
4+++ b/src/maasserver/workflow/bootresource.py
5@@ -2,14 +2,13 @@ import asyncio
6 from asyncio import gather
7 from dataclasses import dataclass, field, replace
8 from datetime import datetime, timedelta
9-import random
10 from typing import Coroutine, Sequence
11
12 from aiohttp.client_exceptions import ClientError
13 from temporalio import activity, workflow
14 from temporalio.common import RetryPolicy, WorkflowIDReusePolicy
15 from temporalio.exceptions import ApplicationError
16-from temporalio.workflow import ActivityCancellationType
17+from temporalio.workflow import ActivityCancellationType, random
18
19 from maasserver.utils.bootresource import (
20 get_bootresource_store_path,
21@@ -282,6 +281,9 @@ class SyncBootResourcesWorkflow:
22 workflow.logger.info("Sync complete")
23 return
24
25+ # Use a random generator from the temporal sdk in order to keep the workflow deterministic.
26+ random_generator = random()
27+
28 sync_jobs: list[Coroutine] = []
29 for res in input.resources:
30 missing: set[str] = set()
31@@ -298,9 +300,12 @@ class SyncBootResourcesWorkflow:
32 for reg in sources
33 for ep in endpoints[reg]
34 ]
35+ # In order to balance the workload on the regions we randomize the order of the source_list.
36 new_res = replace(
37 res,
38- source_list=random.sample(eps, min(len(eps), MAX_SOURCES)),
39+ source_list=random_generator.sample(
40+ eps, min(len(eps), MAX_SOURCES)
41+ ),
42 )
43 for region in missing:
44 sync_jobs.append(_schedule(new_res, region))

Subscribers

People subscribed via source and target branches