Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that UUID is retrieved from database on workflow restart. #5623

Merged
merged 12 commits into from
Aug 3, 2023
10 changes: 6 additions & 4 deletions cylc/flow/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ def __init__(self, reg: str, options: Values) -> None:
workflow=self.workflow,
)
self.id = self.tokens.id
self.uuid_str = str(uuid4())
self.options = options
self.template_vars = get_template_vars(self.options)

Expand All @@ -306,6 +305,9 @@ def __init__(self, reg: str, options: Values) -> None:
pub_d=os.path.join(self.workflow_run_dir, 'log')
)
self.is_restart = Path(self.workflow_db_mgr.pri_path).is_file()
if not self.is_restart:
self.uuid_str = str(uuid4())

# Map used to track incomplete remote inits for restart
# {install_target: platform}
self.incomplete_ri_map: Dict[str, Dict] = {}
Expand Down Expand Up @@ -393,7 +395,6 @@ async def initialise(self):
self.bad_hosts,
self.reset_inactivity_timer
)
self.task_events_mgr.uuid_str = self.uuid_str

self.task_job_mgr = TaskJobManager(
self.workflow,
Expand All @@ -403,7 +404,6 @@ async def initialise(self):
self.data_store_mgr,
self.bad_hosts
)
self.task_job_mgr.task_remote_mgr.uuid_str = self.uuid_str

self.profiler = Profiler(self, self.options.profile_mode)

Expand Down Expand Up @@ -701,8 +701,10 @@ async def start(self):
self.server.thread.start()
barrier.wait()

self._configure_contact()
await self.configure()
self.task_events_mgr.uuid_str = self.uuid_str
self.task_job_mgr.task_remote_mgr.uuid_str = self.uuid_str
self._configure_contact()
except (KeyboardInterrupt, asyncio.CancelledError, Exception) as exc:
await self.handle_exception(exc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ INSERT INTO inheritance VALUES('root','["root"]');
INSERT INTO inheritance VALUES('foo','["foo", "root"]');
CREATE TABLE workflow_params(key TEXT, value TEXT, PRIMARY KEY(key));
INSERT INTO workflow_params VALUES('cylc_version', '8.0.0');
INSERT INTO workflow_params VALUES('uuid_str', 'Something');
CREATE TABLE workflow_template_vars(key TEXT, value TEXT, PRIMARY KEY(key));
CREATE TABLE task_action_timers(cycle TEXT, name TEXT, ctx_key TEXT, ctx TEXT, delays TEXT, num INTEGER, delay TEXT, timeout TEXT, PRIMARY KEY(cycle, name, ctx_key));
INSERT INTO task_action_timers VALUES('1','foo','"poll_timer"','["tuple", [[99, "running"]]]','[]',0,NULL,NULL);
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import asyncio
import logging
from pathlib import Path
import pytest
import re
from typing import Any, Callable

from cylc.flow.exceptions import CylcError
Expand Down Expand Up @@ -292,3 +294,31 @@ def mock_auto_restart(*a, **k):

assert log_filter(log, level=logging.ERROR, contains=err_msg)
assert TRACEBACK_MSG in log.text


async def test_uuid_unchanged_on_restart(
one: Scheduler,
scheduler: Callable,
start: Callable,
):
"""Restart gets UUID from Database:

See https://github.com/cylc/cylc-flow/issues/5615

Process:
* Create a scheduler then shut it down.
* Create a new scheduler for the same workflow and check that it has
retrieved the UUID from the Daatabase.
"""
uuid_re = re.compile('CYLC_WORKFLOW_UUID=(.*)')
contact_file = Path(one.workflow_run_dir) / '.service/contact'

async with start(one):
pass

schd = scheduler(one.workflow_name, paused_start=True)
async with start(schd):
# UUID in contact file should be the same as that set in the database
# and the scheduler.
cf_uuid = uuid_re.findall(contact_file.read_text())[0]
assert schd.uuid_str == cf_uuid
wxtim marked this conversation as resolved.
Show resolved Hide resolved