Skip to content

Commit 0fb3e13

Browse files
fjettergjoseph92
authored andcommitted
Ensure restart clears taskgroups et al (dask#6944)
1 parent a7a8f44 commit 0fb3e13

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

distributed/scheduler.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,21 @@ def new_task(
14311431

14321432
return ts
14331433

1434+
def _clear_task_state(self):
1435+
1436+
logger.debug("Clear task state")
1437+
for collection in [
1438+
self.unrunnable,
1439+
self.erred_tasks,
1440+
self.computations,
1441+
self.task_prefixes,
1442+
self.task_groups,
1443+
self.task_metadata,
1444+
self.unknown_durations,
1445+
self.replicated_tasks,
1446+
]:
1447+
collection.clear()
1448+
14341449
#####################
14351450
# State Transitions #
14361451
#####################
@@ -3098,8 +3113,6 @@ def __init__(
30983113
resources = {}
30993114
aliases = {}
31003115

3101-
self._task_state_collections = [unrunnable]
3102-
31033116
self._worker_collections = [
31043117
workers,
31053118
host_info,
@@ -3400,7 +3413,7 @@ async def start_unsafe(self):
34003413

34013414
enable_gc_diagnosis()
34023415

3403-
self.clear_task_state()
3416+
self._clear_task_state()
34043417

34053418
for addr in self._start_address:
34063419
await self.listen(
@@ -5183,13 +5196,6 @@ async def gather(self, keys, serializers=None):
51835196
self.log_event("all", {"action": "gather", "count": len(keys)})
51845197
return result
51855198

5186-
def clear_task_state(self):
5187-
# XXX what about nested state such as ClientState.wants_what
5188-
# (see also fire-and-forget...)
5189-
logger.info("Clear task state")
5190-
for collection in self._task_state_collections:
5191-
collection.clear()
5192-
51935199
@log_errors
51945200
async def restart(self, client=None, timeout=30, wait_for_workers=True):
51955201
"""
@@ -5229,9 +5235,8 @@ async def restart(self, client=None, timeout=30, wait_for_workers=True):
52295235
stimulus_id=stimulus_id,
52305236
)
52315237

5232-
self.clear_task_state()
5233-
self.erred_tasks.clear()
5234-
self.computations.clear()
5238+
self._clear_task_state()
5239+
assert not self.tasks
52355240
self.report({"op": "restart"})
52365241

52375242
for plugin in list(self.plugins.values()):

distributed/tests/test_scheduler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,16 @@ async def test_ready_remove_worker(s, a, b):
615615

616616
@gen_cluster(client=True, Worker=Nanny, timeout=60)
617617
async def test_restart(c, s, a, b):
618+
618619
futures = c.map(inc, range(20))
619620
await wait(futures)
620621

621622
await s.restart()
622623

624+
assert not s.computations
625+
assert not s.task_prefixes
626+
assert not s.task_groups
627+
623628
assert len(s.workers) == 2
624629

625630
for ws in s.workers.values():

0 commit comments

Comments
 (0)