Skip to content

[Data] Make shuffle regroup operator the owner of flight server - #67143

Merged
owenowenisme merged 3 commits into
ray-project:masterfrom
owenowenisme:owenowenisme/Make-reducer-op-the-owner-of-shuffle-server
Nov 20, 2026
Merged

owenowenisme merged 3 commits into
ray-project:masterfrom
owenowenisme:owenowenisme/Make-reducer-op-the-owner-of-shuffle-server

Conversation

@owenowenisme

Copy link
Copy Markdown
Member

Description

As title, with this we don't have to use detached actor for flight server.

Should rebase after #67130 merged

Related issues

Link related issues: "Fixes #1234", "Closes #1234", or "Related to #1234".

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

@owenowenisme
owenowenisme requested a review from a team as a code owner October 18, 2026 10:58
@owenowenisme owenowenisme added the data Ray Data-related issues label Oct 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the disk-based hash shuffle implementation in Ray Data by replacing the custom DiskHashShuffleMapOp with a standard MapOperator that utilizes a new DiskShuffleWriteFn block transform. It also replaces the hardcoded _BLOCKING_MATERIALIZING_OPERATORS list with a dynamic is_blocking_materializing property on PhysicalOperator to streamline backpressure and resource allocation. Additionally, DiskHashShuffleReduceOp is updated to directly manage the lifecycle of ShuffleFileServer actors. The review feedback identifies two potential performance bottlenecks on the main executor thread: sequentially calling ray.get inside _add_input_inner and blocking the thread with a 5-second ray.wait timeout during teardown_disk_shuffle. It is recommended to batch the ray.get calls and make the directory cleanup asynchronous or fire-and-forget.

Comment on lines +460 to +461
if cleanup_refs:
ray.wait(cleanup_refs, num_returns=len(cleanup_refs), timeout=5.0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Calling ray.wait with a 5-second timeout inside teardown_disk_shuffle blocks the main executor thread during operator shutdown. In scenarios where multiple datasets are running concurrently or sequentially on the same driver, blocking the executor thread for up to 5 seconds will pause all other active datasets.\n\nSince directory cleanup is a fire-and-forget operation, consider submitting the cleanup tasks without waiting for them to complete on the main thread, or offloading the wait to a background thread.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ig this could be turned into a fire and forget call. but could also be ok to leave it as it is as this is only affecting teardown

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 4bb30ca. Configure here.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Nov 1, 2026

@viiccwen viiccwen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

left comment!

Comment on lines +422 to +424
for server in self._file_servers.values():
ray.kill(server, no_restart=True)
teardown_disk_shuffle(self._file_servers.keys())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_file_servers only tracks nodes after the reducer receives their handles. If execution stops before that, these nodes won't be cleaned up, leaving .shf files on disk.

Maybe we can track mapper nodes separately to make sure the files are cleaned up even if execution stops early?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah I planned to deal with that in another PR, this one focus on the server.

Comment on lines 378 to 380

@viiccwen viiccwen Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you add disk_shuffle_dirs, replace with _, staging_dir = disk_shuffle_dirs(shuffle_id).
Then remove unused import tempfile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed

Comment on lines +444 to +449
if (
isinstance(writer, TaskPoolMapOperator)
and len(writer._logical_operators) <= 1
and writer.input_dependencies
):
return writer.input_dependencies[0].num_output_rows_total()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The reducer seems to know too much about the upstream operator here, like checking TaskPoolMapOperator, accessing _logical_operators, and going through writer.input_dependencies[0].

Maybe we can let the planner pass the row count source directly, so the reducer doesn't need to depend on these implementation details.

But this would also require changing the upstream contract. WDYT?

@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Nov 13, 2026
Signed-off-by: You-Cheng Lin <[email protected]>
@owenowenisme
owenowenisme force-pushed the owenowenisme/Make-reducer-op-the-owner-of-shuffle-server branch from 4bb30ca to 98dce74 Compare November 18, 2026 10:58
@owenowenisme owenowenisme changed the title [Data] Make shuffle reduce operator the owner of flight server [Data] Make shuffle regroup operator the owner of flight server Nov 18, 2026
@owenowenisme owenowenisme added the go add ONLY when ready to merge, run all tests label Nov 20, 2026
@owenowenisme
owenowenisme enabled auto-merge (squash) November 20, 2026 09:55
Signed-off-by: You-Cheng Lin <[email protected]>
@github-actions
github-actions Bot disabled auto-merge November 20, 2026 12:10
@owenowenisme
owenowenisme merged commit 015f52c into ray-project:master Nov 20, 2026
5 checks passed
elliot-barn added a commit that referenced this pull request Nov 23, 2026
…nto releases/2.61.0 (#68472)

## Description

Cherry-pick of #68433 (`1729626bbb`) onto `releases/2.61.0`. Lets the
upstream read or map fuse into the disk-shuffle writer, and sets the
polars thread limit inside the task rather than through the runtime env.

The pick applied without conflicts. Seven master commits that touch the
same files are not on the release branch (#67143, #68158, #68202 and its
revert #68383, #68319, #67570, #68118), so the picked files differ from
master in five places. Reviewers from Data, please confirm none of those
is a prerequisite.

## Testing

Ran locally against the `releases/2.61.0` wheel (`7c8ca5ea51`) with the
picked files overlaid: `test_hash_shuffle_v2.py`,
`test_operator_fusion.py` and `test_execution_optimizer_advanced.py`,
232 passed, 2 skipped.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: You-Cheng Lin <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
Co-authored-by: You-Cheng Lin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray fails to serialize self-reference objects

3 participants