-
-
Notifications
You must be signed in to change notification settings - Fork 719
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
Refactor all event handlers #6410
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
052828c
Refactor all Worker event handlers
crusaderky 6a0bb98
Merge branch 'main' into WSMR/refactor_handlers
crusaderky 8ba2605
Merge branch 'main' into WSMR/refactor_handlers
crusaderky b65ad99
Remove public transition method
crusaderky cf58b5f
Merge branch 'main' into WSMR/refactor_handlers
crusaderky 72b11ed
Merge branch 'main' into WSMR/refactor_handlers
crusaderky a9f6439
polish
crusaderky 249e819
Fix failing tests
crusaderky 42d399f
Merge branch 'main' into WSMR/refactor_handlers
crusaderky 089c545
use generic Collection[str] in events
crusaderky 89b6d36
name all handle_event dispatcher
crusaderky b9cb485
Merge branch 'main' into WSMR/refactor_handlers
crusaderky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1088,7 +1088,7 @@ def __init__(self, key: str, run_spec: object): | |||||
self.has_lost_dependencies = False | ||||||
self.host_restrictions = None # type: ignore | ||||||
self.worker_restrictions = None # type: ignore | ||||||
self.resource_restrictions = None # type: ignore | ||||||
self.resource_restrictions = {} | ||||||
self.loose_restrictions = False | ||||||
self.actor = False | ||||||
self.prefix = None # type: ignore | ||||||
|
@@ -2670,14 +2670,12 @@ def valid_workers(self, ts: TaskState) -> set: # set[WorkerState] | None | |||||
return s | ||||||
|
||||||
def consume_resources(self, ts: TaskState, ws: WorkerState): | ||||||
if ts.resource_restrictions: | ||||||
for r, required in ts.resource_restrictions.items(): | ||||||
ws.used_resources[r] += required | ||||||
for r, required in ts.resource_restrictions.items(): | ||||||
ws.used_resources[r] += required | ||||||
|
||||||
def release_resources(self, ts: TaskState, ws: WorkerState): | ||||||
if ts.resource_restrictions: | ||||||
for r, required in ts.resource_restrictions.items(): | ||||||
ws.used_resources[r] -= required | ||||||
for r, required in ts.resource_restrictions.items(): | ||||||
ws.used_resources[r] -= required | ||||||
|
||||||
def coerce_hostname(self, host): | ||||||
""" | ||||||
|
@@ -7092,29 +7090,28 @@ def adaptive_target(self, target_duration=None): | |||||
to_close = self.workers_to_close() | ||||||
return len(self.workers) - len(to_close) | ||||||
|
||||||
def request_acquire_replicas(self, addr: str, keys: list, *, stimulus_id: str): | ||||||
def request_acquire_replicas( | ||||||
self, addr: str, keys: Iterable[str], *, stimulus_id: str | ||||||
) -> None: | ||||||
"""Asynchronously ask a worker to acquire a replica of the listed keys from | ||||||
other workers. This is a fire-and-forget operation which offers no feedback for | ||||||
success or failure, and is intended for housekeeping and not for computation. | ||||||
""" | ||||||
who_has = {} | ||||||
for key in keys: | ||||||
ts = self.tasks[key] | ||||||
who_has[key] = {ws.address for ws in ts.who_has} | ||||||
|
||||||
who_has = {key: [ws.address for ws in self.tasks[key].who_has] for key in keys} | ||||||
if self.validate: | ||||||
assert all(who_has.values()) | ||||||
|
||||||
self.stream_comms[addr].send( | ||||||
{ | ||||||
"op": "acquire-replicas", | ||||||
"keys": keys, | ||||||
"who_has": who_has, | ||||||
"stimulus_id": stimulus_id, | ||||||
}, | ||||||
) | ||||||
|
||||||
def request_remove_replicas(self, addr: str, keys: list, *, stimulus_id: str): | ||||||
def request_remove_replicas( | ||||||
self, addr: str, keys: list[str], *, stimulus_id: str | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because the variable is sent as-is through the msgpack RPC, so only a list, set, or tuple are accepted. |
||||||
) -> None: | ||||||
"""Asynchronously ask a worker to discard its replica of the listed keys. | ||||||
This must never be used to destroy the last replica of a key. This is a | ||||||
fire-and-forget operation, intended for housekeeping and not for computation. | ||||||
|
@@ -7125,15 +7122,14 @@ def request_remove_replicas(self, addr: str, keys: list, *, stimulus_id: str): | |||||
to re-add itself to who_has. If the worker agrees to discard the task, there is | ||||||
no feedback. | ||||||
""" | ||||||
ws: WorkerState = self.workers[addr] | ||||||
validate = self.validate | ||||||
ws = self.workers[addr] | ||||||
|
||||||
# The scheduler immediately forgets about the replica and suggests the worker to | ||||||
# drop it. The worker may refuse, at which point it will send back an add-keys | ||||||
# message to reinstate it. | ||||||
for key in keys: | ||||||
ts: TaskState = self.tasks[key] | ||||||
if validate: | ||||||
ts = self.tasks[key] | ||||||
if self.validate: | ||||||
# Do not destroy the last copy | ||||||
assert len(ts.who_has) > 1 | ||||||
self.remove_replica(ts, ws) | ||||||
|
@@ -7314,22 +7310,16 @@ def _task_to_msg( | |||||
dts.key: [ws.address for ws in dts.who_has] for dts in ts.dependencies | ||||||
}, | ||||||
"nbytes": {dts.key: dts.nbytes for dts in ts.dependencies}, | ||||||
"run_spec": ts.run_spec, | ||||||
"resource_restrictions": ts.resource_restrictions, | ||||||
"actor": ts.actor, | ||||||
"annotations": ts.annotations, | ||||||
} | ||||||
if state.validate: | ||||||
assert all(msg["who_has"].values()) | ||||||
|
||||||
if ts.resource_restrictions: | ||||||
msg["resource_restrictions"] = ts.resource_restrictions | ||||||
if ts.actor: | ||||||
msg["actor"] = True | ||||||
|
||||||
if isinstance(ts.run_spec, dict): | ||||||
msg.update(ts.run_spec) | ||||||
else: | ||||||
msg["task"] = ts.run_spec | ||||||
|
||||||
if ts.annotations: | ||||||
msg["annotations"] = ts.annotations | ||||||
if isinstance(msg["run_spec"], dict): | ||||||
assert set(msg["run_spec"]).issubset({"function", "args", "kwargs"}) | ||||||
assert msg["run_spec"].get("function") | ||||||
|
||||||
return msg | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was changed from a list to a set, was that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from a set to a list. yes, as the set doesn't offer any useful feature here and a list is fractionally faster. This also makes it coherent with Scheduler.get_who_has.