Repository navigation
[Data] Disk shuffle map tasks append to one file per partition per node - #68613
owenowenisme wants to merge 2 commits into
Conversation
Signed-off-by: You-Cheng Lin <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request optimizes Ray Data's disk shuffle mechanism by appending map task outputs to shared per-partition files on each node instead of creating individual files per task. It introduces self-framed records with map IDs and attempt tokens to handle task retries, and simplifies the metadata and Flight fetch logic. The review feedback suggests slicing the shared sizes array by partition_id in _partition_input to support passing the full sizes array in a single shared ObjectRef from the driver, along with corresponding updates to the unit tests to mock and assert against this 2D array representation.
Signed-off-by: You-Cheng Lin <[email protected]>
| if committed_attempts.get(map_id) == attempt_token: | ||
| ipc_buf = os.pread(fd, length, pos + header_size) | ||
| out.append((map_id, _read_ipc(ipc_buf, compression))) | ||
| pos += header_size + length |
There was a problem hiding this comment.
If the worker gets SIGKILLed (OOM killer, Ray's memory monitor) while the writev in _append_record is running, the file keeps the bytes written so far, and the header still says the full length. The retry and the other map tasks on the node append after it, so the region end is past it. This line then jumps from the partial record by its full length into the middle of a later record, reads payload bytes as the next header, and fails with torn record. The torn checks only catch a partial record that is last in the region, which is the case the test covers.
Repro with the public API on ea91957, one node: SHUFFLE_V2 + use_disk_based_hash_shuffle=True, four 300 MiB blocks of random bytes, repartition(2, keys=["k"]). A thread in the driver kill -9s the first worker that has a node_p*.shf open. Ray reruns the map task, then the reduce fails, 3 of 3 runs:
RuntimeError: torn record at 157846526: 10040076413216674997 bytes run past region end 634945162
The same kill on the merge base 88648d8 (worker writing map_0.shf.tmp) gave all 307,200 rows with correct per-row crc32, 3 of 3 runs. Without the kill both sides return all rows. Retrying the reduce doesn't help, since the bytes stay in the file.
One way that keeps the metadata per node: the regroup already sees every committed (offset, length). If the committed lengths of a node file add up to its end, nothing else is in the file and this walk is safe. If they don't, send the committed offsets for that file only, and let the reducer jump to them instead of trusting a dead record's header.
Description
Why
In the disk-based hash shuffle every map task seals its own
map_{i}.shffile. A reducer for partitionpthen has to fetch one byte range from every map task, and the driver has to tell it where each range is. Both scale with map tasks × partitions. At TPC-H sf1000 that is about 8,000 tasks × 1,000 partitions with 8M ranges across the job, roughly 260 MB of range metadata that every reduce task unpickles before it can start, and thousands of small Flight ranges per reducer.This PR makes the files per node instead of per task. All map tasks on a node append partition
pto the samenode_p{p}.shf. A reducer fetches one file per node, and the driver only tracks one size per node per partition. Everything now scales with nodes × partitions. (Can further makes them smaller if when AQE lands in the future)How the appends work without a coordinator
Each map task writes one record per partition with one
writevon a file opened withO_APPEND. The kernel takes the inode lock for the duration of the write and places it at the current end of file, so two tasks appending to the same file can never interleave bytes. After the write the task reads back the descriptor position withlseek, andposition - record sizeis the record's offset.The driver folds each handle's per-partition
(offset, length)into a runningmax(offset + length)per node, which is the size of that node's file up to its last committed record. That is all the reducer needs.Why records carry an attempt token
A map task can die after appending some of its records, and Ray then reruns it. Before, the rerun simply overwrote the task's own file. Now the records sit in a file shared with other tasks, so they cannot be removed, and the rerun appends a second copy, possibly from another node.
So the reader filters instead. Every record has a 24-byte header: length, map task id, and a random 64-bit token drawn once per task attempt. The driver only ever receives the handle of the attempt that finished, so it knows the one token per map id that counts. Reducers decode a record only when its token matches, and skip the rest.
BTW, Celeborn also handle retries the same way.
Decoded records are sorted by map id, so the reduce input is the same on every run.
Results (sf1000, measured on this branch)
Full-output joins, 32 nodes, same cluster, min of 2:
The reduce operator went from 108 s to 51 s on the inner join; map operators are unchanged. Master spilled 0-71 GB per run, this branch 0.
All 22 TPC-H queries, 8 nodes: 1512 s vs 1586 s total (0.95x), no query slower, 0 spill in all runs, identical results.