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 uniqueness of steal stimulus ID #5620

Merged
merged 3 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions distributed/stealing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import logging
import uuid
from collections import defaultdict, deque
from math import log2
from time import time
Expand Down Expand Up @@ -233,7 +234,9 @@ def move_task_request(self, ts, victim, thief) -> str:
try:
if ts in self.in_flight:
return "in-flight"
stimulus_id = f"steal-{time()}"
# Stimulus IDs are used to verify the response, see
# `move_task_confirm`. Therefore, this must be truly unique.
stimulus_id = f"steal-{uuid.uuid4().hex}"

key = ts.key
self.remove_key_from_stealable(ts)
Expand Down Expand Up @@ -291,7 +294,7 @@ async def move_task_confirm(self, *, key, state, stimulus_id, worker=None):
self.in_flight[ts] = d
return
except KeyError:
self.log(("already-aborted", key, state, stimulus_id))
self.log(("already-aborted", key, state, worker, stimulus_id))
return

thief = d["thief"]
Expand Down
37 changes: 37 additions & 0 deletions distributed/tests/test_steal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,3 +1193,40 @@ async def test_correct_bad_time_estimate(c, s, *workers):
assert any(s.tasks[f.key] in steal.key_stealable for f in futures)
await wait(futures)
assert all(w.data for w in workers), [sorted(w.data) for w in workers]


@gen_cluster(client=True)
async def test_steal_stimulus_id_unique(c, s, *workers):
steal = s.extensions["stealing"]
num_futs = 1_000
from distributed import Lock
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be at the top of the module


lock = Lock()
async with lock:

def blocked(x, lock):
lock.acquire()

# Setup all tasks on worker 0 such that victim/thief relation is the
# same for all tasks.
futures = c.map(
blocked, range(num_futs), lock=lock, workers=[workers[0].address]
)
# Ensure all tasks are assigned to the worker since otherwise the
# move_task_request fails.
while len(workers[0].tasks) != num_futs:
await asyncio.sleep(0.1)
tasks = [s.tasks[f.key] for f in futures]
w0 = s.workers[workers[0].address]
w1 = s.workers[workers[1].address]
# Generating the move task requests as fast as possible increases the
# chance of duplicates if the uniqueness is not guaranteed.
for ts in tasks:
steal.move_task_request(ts, w0, w1)
stimulus_ids = set()
# Values stored in in_flight are used for response verification.
# Therefore all stimulus IDs are stored here and must be unique
for dct in steal.in_flight.values():
stimulus_ids.add(dct["stimulus_id"])
assert len(stimulus_ids) == num_futs
await c.cancel(futures)