Repository navigation
[Data] (Data Fault Tolerance 3/n) Support lineage tracking for fan-ins - #66136
Conversation
Signed-off-by: davik <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request enhances the LineageTracker to support fan-in lineage tracking and failure recovery by transitioning plan-to-child block lineages from lists to sets, passing plan_id during task submission, and discharging plans upon submission rather than completion. It also adds extensive unit tests for fan-in, diamond, and all-to-all recovery scenarios. The review feedback highlights a critical lack of idempotency for re-executed task submissions, which could cause crashes on retries. To address this, it is recommended to dynamically track submitted plans on the task nodes, clear this status during reconstruction tracing, defensively use .pop() instead of del to avoid potential KeyErrors, and update the test suite to assert idempotent behavior.
| re_executed_task_node = self._data_task_id_to_task_node.get(data_task_id) | ||
| if plan_id is not None: | ||
| if re_executed_task_node is None: | ||
| raise ValueError( | ||
| f"Task {data_task_id} was submitted as a re-execution " | ||
| f"of plan {plan_id}. However, the task is not registered " | ||
| "as part of the execution graph. Either the plan was incorrectly " | ||
| "attributed to this task, or the task was incorrectly removed " | ||
| "from the execution graph." | ||
| ) | ||
| if plan_id not in re_executed_task_node.plan_to_child_block_lineages: | ||
| raise ValueError( | ||
| f"Task {data_task_id} was submitted as a re-execution " | ||
| f"of plan {plan_id}. However, the plan is not registered " | ||
| "as a known reconstruction plan for this task. Has the " | ||
| "plan been correctly added to all tasks necessary for " | ||
| "the reconstruction?" | ||
| ) |
There was a problem hiding this comment.
Issue: Lack of Idempotency for Re-executed Task Submissions
In distributed systems like Ray, task submissions can be retried or submitted multiple times. Currently, register_task_submission is idempotent for fresh tasks (returning early if the task is already registered). However, for re-executed tasks (where plan_id is not None), the validation checks and dependency-removal logic are executed on every submission.
This causes two major issues on repeated submissions of a re-executed task:
- For the target task:
plan_idis deleted fromplan_to_child_block_lineageson the first submission. A second submission will fail validation with aValueErrorbecauseplan_idis no longer inplan_to_child_block_lineages. - For non-target tasks: The dependencies are removed from the parents' plans on the first submission. A second submission will fail with a
ValueErrorbecause the dependencies are no longer present in the parents' plans.
Solution:
Track which plans have already been submitted for each TaskNode using a dynamic set _submitted_plans. If a task is submitted again for the same plan_id, log it and return early. We also clear this status in _trace_parent_for_reconstruction if the task fails again and needs to be reconstructed.
re_executed_task_node = self._data_task_id_to_task_node.get(data_task_id)
if plan_id is not None:
if re_executed_task_node is None:
raise ValueError(
f"Task {data_task_id} was submitted as a re-execution "
f"of plan {plan_id}. However, the task is not registered "
"as part of the execution graph. Either the plan was incorrectly "
"attributed to this task, or the task was incorrectly removed "
"from the execution graph."
)
if not hasattr(re_executed_task_node, "_submitted_plans"):
re_executed_task_node._submitted_plans = set()
if plan_id in re_executed_task_node._submitted_plans:
logger.debug(
"Repeated submission of data task ID %s with dependencies %s for plan %s",
data_task_id,
dependencies,
plan_id,
)
return
re_executed_task_node._submitted_plans.add(plan_id)
if plan_id not in re_executed_task_node.plan_to_child_block_lineages:
raise ValueError(
f"Task {data_task_id} was submitted as a re-execution "
f"of plan {plan_id}. However, the plan is not registered "
"as a known reconstruction plan for this task. Has the "
"plan been correctly added to all tasks necessary for "
"the reconstruction?"
)| # of the reconstruction has no child to re-produce blocks for, so its | ||
| # lineage for the plan stays empty. | ||
| child_block_lineages = node.plan_to_child_block_lineages.setdefault( | ||
| plan_id_to_attach, [] | ||
| plan_id_to_attach, set() | ||
| ) |
There was a problem hiding this comment.
Improvement: Clear Submitted Status on Reconstruction Tracing
When a task fails again during the same reconstruction plan, it needs to be re-submitted. To allow this, we must clear the plan_id from _submitted_plans when tracing the node for reconstruction again.
| # of the reconstruction has no child to re-produce blocks for, so its | |
| # lineage for the plan stays empty. | |
| child_block_lineages = node.plan_to_child_block_lineages.setdefault( | |
| plan_id_to_attach, [] | |
| plan_id_to_attach, set() | |
| ) | |
| # of the reconstruction has no child to re-produce blocks for, so its | |
| # lineage for the plan stays empty. | |
| child_block_lineages = node.plan_to_child_block_lineages.setdefault( | |
| plan_id_to_attach, set() | |
| ) | |
| if hasattr(node, "_submitted_plans"): | |
| node._submitted_plans.discard(plan_id_to_attach) |
| if plan_id is not None and data_task_id == plan_id: | ||
| del re_executed_task_node.plan_to_child_block_lineages[plan_id] |
There was a problem hiding this comment.
Defensive Programming: Use .pop() instead of del
Using del can raise a KeyError if the key is not present in the dictionary. Using .pop(plan_id, None) is safer and avoids potential crashes.
| if plan_id is not None and data_task_id == plan_id: | |
| del re_executed_task_node.plan_to_child_block_lineages[plan_id] | |
| if plan_id is not None and data_task_id == plan_id: | |
| re_executed_task_node.plan_to_child_block_lineages.pop(plan_id, None) |
| def test_resubmission_of_an_already_claimed_block_raises(): | ||
| """A block the plan owes is claimed once, even while the plan is still live. | ||
|
|
||
| Chain: ``task_0 -> task_1 -> task_2`` | ||
| """ | ||
| tracker = LineageTracker() | ||
| task_ids = [f"task_{i}" for i in range(3)] | ||
| seed_task_id, leaf_task_id = task_ids[0], task_ids[-1] | ||
| output_indices = [0, 1] | ||
|
|
||
| _register_linear_chain(tracker, task_ids, output_indices=output_indices) | ||
|
|
||
| seed_tasks_to_retry, plan_id = tracker.register_task_failed(leaf_task_id) | ||
| assert seed_tasks_to_retry == [seed_task_id] | ||
| tracker.register_task_submission(seed_task_id, dependencies=[], plan_id=plan_id) | ||
| tracker.register_task_complete(seed_task_id, plan_id=plan_id) | ||
|
|
||
| tracker.register_task_submission( | ||
| task_ids[1], | ||
| dependencies=_dependencies(seed_task_id, [0]), | ||
| plan_id=plan_id, | ||
| ) | ||
|
|
||
| with pytest.raises(ValueError, match=_BLOCK_NOT_OWED): | ||
| tracker.register_task_submission( | ||
| task_ids[1], | ||
| dependencies=_dependencies(seed_task_id, [0]), | ||
| plan_id=plan_id, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Test Update: Assert Idempotency instead of ValueError
Since duplicate submissions of re-executed tasks should be idempotent and safely ignored (matching the behavior of fresh tasks), we should update this test to assert that duplicate submissions do not raise an error.
def test_resubmission_of_an_already_claimed_block_is_idempotent():
"""A duplicate submission of a re-executed task is idempotent and does not raise."""
tracker = LineageTracker()
task_ids = [f"task_{i}" for i in range(3)]
seed_task_id, leaf_task_id = task_ids[0], task_ids[-1]
output_indices = [0, 1]
_register_linear_chain(tracker, task_ids, output_indices=output_indices)
seed_tasks_to_retry, plan_id = tracker.register_task_failed(leaf_task_id)
assert seed_tasks_to_retry == [seed_task_id]
tracker.register_task_submission(seed_task_id, dependencies=[], plan_id=plan_id)
tracker.register_task_complete(seed_task_id, plan_id=plan_id)
tracker.register_task_submission(
task_ids[1],
dependencies=_dependencies(seed_task_id, [0]),
plan_id=plan_id,
)
# Duplicate submission should be safely ignored and not raise an error
tracker.register_task_submission(
task_ids[1],
dependencies=_dependencies(seed_task_id, [0]),
plan_id=plan_id,
)Signed-off-by: davik <[email protected]>
There was a problem hiding this comment.
LGTM, with minor suggestions.
I like Action interface that we can use to parameterize the tests, potentially we can unify all unit tests into this format.
My only concern is that we are also introducing the all to all graph representation for some tests. Too many different test abstractions could get confusing.
| If an unregistered task is submitted with a ``plan_id``. | ||
| Invariant: only a task that has already been submitted | ||
| can be a re-execution of a reconstruction plan. | ||
| If ``plan_id`` no longer claims the task, or no longer | ||
| owes it one of the blocks it asks a parent for. | ||
| Invariant: a plan claims each block it owes exactly | ||
| once, so within a plan, for any output block, there can | ||
| be at most one reconstruction of it. |
There was a problem hiding this comment.
This is a little difficult to understand. Can we rephrase this docstring?
| parent_to_dependencies[dependency.parent_data_task_id] = [] | ||
| parent_to_dependencies[dependency.parent_data_task_id].append( | ||
| dependency.output_index | ||
| child_block_lineages = parent_task_node.plan_to_child_block_lineages |
There was a problem hiding this comment.
A little verbose, but can we rename child_block_lineages to parent_task_child_block_lineages for clarity
| child_block_lineages = parent_task_node.plan_to_child_block_lineages | |
| parent_task_child_block_lineages = parent_task_node.plan_to_child_block_lineages |
| Completion does not discharge a plan -- submission does -- so on a | ||
| re-execution attempt a task may complete before the downstream tasks | ||
| consuming its blocks are resubmitted. |
There was a problem hiding this comment.
| Completion does not discharge a plan -- submission does -- so on a | |
| re-execution attempt a task may complete before the downstream tasks | |
| consuming its blocks are resubmitted. | |
| Completing a task does not remove anything from its plan set. Plan set entries are | |
| removed in ``register_task_submission``, when the child that consumes the | |
| block is resubmitted. |
| ExpectObjectReuseStatus( | ||
| _SEED_TASK_IDS[0], 0, _CHILD_PLAN, ObjectReuseStatus.OBJECT_UNRELATED | ||
| ), | ||
| ExpectPendingChildren(_SEED_TASK_IDS[1], _CHILD_PLAN, {}), | ||
| ExpectObjectReuseStatus( | ||
| _SEED_TASK_IDS[1], 0, _CHILD_PLAN, ObjectReuseStatus.OBJECT_UNRELATED | ||
| ), |
There was a problem hiding this comment.
We should document that this is unrelated because there is no active plan.
| ExpectObjectReuseStatus( | |
| _SEED_TASK_IDS[0], 0, _CHILD_PLAN, ObjectReuseStatus.OBJECT_UNRELATED | |
| ), | |
| ExpectPendingChildren(_SEED_TASK_IDS[1], _CHILD_PLAN, {}), | |
| ExpectObjectReuseStatus( | |
| _SEED_TASK_IDS[1], 0, _CHILD_PLAN, ObjectReuseStatus.OBJECT_UNRELATED | |
| ), | |
| # Since there is no active reconstruction plan at this point (the reconstruction child task has already been submitted), any objects for this plan should be unrelated | |
| ExpectObjectReuseStatus( | |
| _SEED_TASK_IDS[0], 0, _CHILD_PLAN, ObjectReuseStatus.OBJECT_UNRELATED | |
| ), | |
| ExpectPendingChildren(_SEED_TASK_IDS[1], _CHILD_PLAN, {}), | |
| ExpectObjectReuseStatus( | |
| _SEED_TASK_IDS[1], 0, _CHILD_PLAN, ObjectReuseStatus.OBJECT_UNRELATED | |
| ), |
| # Second output of the seed is ready to be scheduled. | ||
| Submit(_RIGHT, {_SEED: [1]}, plan=_PLAN), | ||
| ExpectPendingChildren(_SEED, _PLAN, {}), | ||
| ExpectObjectReuseStatus(_SEED, 0, _PLAN, ObjectReuseStatus.OBJECT_UNRELATED), |
There was a problem hiding this comment.
| ExpectObjectReuseStatus(_SEED, 0, _PLAN, ObjectReuseStatus.OBJECT_UNRELATED), | |
| # Because both pending children tasks of the seed task are submitted, we have removed all the child dependencies of the seed task (specific to this plan), and any objects queried for this plan should be unrelated | |
| ExpectObjectReuseStatus(_SEED, 0, _PLAN, ObjectReuseStatus.OBJECT_UNRELATED), |
There was a problem hiding this comment.
Maybe we should make this logic more explicit
| # Right branch finishes first. | ||
| ExpectPendingChildren(_RIGHT, _PLAN, _PENDING_COMMON_CHILD), | ||
| # Left branch finishes second. | ||
| ExpectPendingChildren(_LEFT, _PLAN, _PENDING_COMMON_CHILD), | ||
| ] |
There was a problem hiding this comment.
Nit: This is slightly confusing to me (and I may be conflating what is the test setup and the test assertion here), but I'm not sure why this is true.
We don't make assumptions about the ordering of task completion, so it seems like this is test setup/scenario. Maybe we should document that i.e. by saying ("Assume right branch finishes first")
There was a problem hiding this comment.
Oh yeah, this is not saying right branch has to finish first here. We're just saying let's suppose right branch finishes here first. I'll update the parent.
| *_complete_stage(graph, 0), | ||
| *_submit_stage(graph, 2), | ||
| *_complete_stage(graph, 1), | ||
| # The tasks of the failed stage that never fail finished first. |
There was a problem hiding this comment.
Can we re-word this comment? Seems a little confusing.
| *_expect_claims_on_stage(graph, 1, _SECOND_FAILURE_PLAN, pending_positions=[]), | ||
| ExpectPendingChildren(second_task_id, _SECOND_FAILURE_PLAN, {}), | ||
| ExpectObjectReuseStatus( | ||
| second_task_id, 0, _SECOND_FAILURE_PLAN, ObjectReuseStatus.OBJECT_NEW | ||
| ), |
There was a problem hiding this comment.
Nit: I think it's a little convoluted for us to interleave directly using the API functions (ExpectPendingChildren, ExpObjReuseStatus()) and indirectly (_expect_claims_on_stage). Maybe we can use indirect helpers consistently for this all to all graph section?
Signed-off-by: davik <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 53154b7. Configure here.
| dependency_to_remove | ||
| ) | ||
| if not parent_task_child_block_lineages[plan_id]: | ||
| del parent_task_child_block_lineages[plan_id] |
There was a problem hiding this comment.
Discharged parent plans skip validation
Medium Severity
When a reconstruction submit finds that a parent no longer carries the given plan_id, that dependency is skipped instead of rejected. Removing the last owed block deletes the parent's plan entry mid-loop, so later dependencies in the same call are ignored. An invalid or duplicate register_task_submission can then succeed, and the owed-block check becomes order-dependent, violating the plan's one-claim invariant.
Reviewed by Cursor Bugbot for commit 53154b7. Configure here.
ray-project#66136) ## Description **Note**: This PR is a no-op and simply adds additional functionality to the Ray Data lineage tracking framework to support fan-out tasks. This PR builds on top of ray-project#65642 to support pipelines with fan-ins on the lineage tracking. Here we define *fan-in* operators as operators whose tasks can take input blocks from more than one upstream operator tasks. At a high level, we extend the plan concept discussed in ray-project#65642 via the following steps: <img width="1035" height="666" alt="image" src="https://github.com/user-attachments/assets/792b9fa0-6b62-4889-b573-c634b7229325" /> As discussed before, the steps for constructing the plan itself is as follows: > 1. When a task fails, we set that task as the `target task`. A reconstruction plan ID associated with the target task is created. > 2. From there, we begin walking up the task lineage graph. For each upstream parent, we create a plan entry that tracks the dependencies produced by that parent task that are necessary to reconstruct the downstream tasks that ultimately leads to the target task. > 3. Once we've reached the root, we begin resubmission starting from the root task. > 4. For each resubmitted task that completes, we check its reconstruction plan in the lineage graph and only pass the outputs that are needed in the plan to downstream tasks. > 5. This continues until the target task is reconstructed. The main extension for supporting fan-ins is: As we walk up the graph when creating the plan, we must ensure that we visit all parents instead of assuming only a single parent. This will allow us to create plans that support fan-in operators. #### Bug fix Another change we've added to the lineage tracker on this PR is to address the issue mentioned in ray-project#65642 (comment). When we submit a reconstruction task, we now remove the submitted task from the set of children pending dependencies on the parent's plan instead of simply removing the plan when the parent task completes. This is necessary because it's possible for a reconstruction task to still be executing when another reconstruction attempt that needs to re-execute the same task is triggered. Consider the following scenario that was possible prior to this PR: <img width="1652" height="1087" alt="image" src="https://github.com/user-attachments/assets/188eabdd-3e80-46e1-bd63-51be8aa643c7" /> Suppose task C failed at some point, triggering reconstruction. Task A has already completed so it's plan is erased. Task B is still executing because it has some unproduced outputs, but the output block Task C needs is ready. So Task C is already executing. At this point, suppose task C's node dies again. Thus we begin reconstruction under the same plan again. Task B's plan entry is duplicated since the previous entry hasn't been erased yet, and Task A's plan is repopulated. <img width="1180" height="1018" alt="image" src="https://github.com/user-attachments/assets/a6f8ab35-5522-4471-a6cc-6e1aeb12e59d" /> Here, notice that once task A completes, task B is essentially going to have two reconstruction attempts happening at the same time for the same plan_id. So let's suppose the earlier task B finishes. This will result in the entire plan being wiped, although the second task B is still executing. <img width="1634" height="1090" alt="Screenshot 2026-09-12 at 7 05 14 PM" src="https://github.com/user-attachments/assets/41682f09-9b04-4bd6-8c6e-3a64a813439f" /> Now if the second task B completes, it's deletion of the plan will result in a key error! Thus, this PR clears the dependency in the parent's plan upon child task submission instead of parent task completion. This means that when the first task B execution produced the dependency needed for task C, we would've cleared task B's plan there when task C was submitted instead of waiting for the executions to double up. Thus, avoiding the issue. ## Related issues ## Additional information --------- Signed-off-by: davik <[email protected]> Co-authored-by: davik <[email protected]>
ray-project#66136) ## Description **Note**: This PR is a no-op and simply adds additional functionality to the Ray Data lineage tracking framework to support fan-out tasks. This PR builds on top of ray-project#65642 to support pipelines with fan-ins on the lineage tracking. Here we define *fan-in* operators as operators whose tasks can take input blocks from more than one upstream operator tasks. At a high level, we extend the plan concept discussed in ray-project#65642 via the following steps: <img width="1035" height="666" alt="image" src="https://github.com/user-attachments/assets/792b9fa0-6b62-4889-b573-c634b7229325" /> As discussed before, the steps for constructing the plan itself is as follows: > 1. When a task fails, we set that task as the `target task`. A reconstruction plan ID associated with the target task is created. > 2. From there, we begin walking up the task lineage graph. For each upstream parent, we create a plan entry that tracks the dependencies produced by that parent task that are necessary to reconstruct the downstream tasks that ultimately leads to the target task. > 3. Once we've reached the root, we begin resubmission starting from the root task. > 4. For each resubmitted task that completes, we check its reconstruction plan in the lineage graph and only pass the outputs that are needed in the plan to downstream tasks. > 5. This continues until the target task is reconstructed. The main extension for supporting fan-ins is: As we walk up the graph when creating the plan, we must ensure that we visit all parents instead of assuming only a single parent. This will allow us to create plans that support fan-in operators. #### Bug fix Another change we've added to the lineage tracker on this PR is to address the issue mentioned in ray-project#65642 (comment). When we submit a reconstruction task, we now remove the submitted task from the set of children pending dependencies on the parent's plan instead of simply removing the plan when the parent task completes. This is necessary because it's possible for a reconstruction task to still be executing when another reconstruction attempt that needs to re-execute the same task is triggered. Consider the following scenario that was possible prior to this PR: <img width="1652" height="1087" alt="image" src="https://github.com/user-attachments/assets/188eabdd-3e80-46e1-bd63-51be8aa643c7" /> Suppose task C failed at some point, triggering reconstruction. Task A has already completed so it's plan is erased. Task B is still executing because it has some unproduced outputs, but the output block Task C needs is ready. So Task C is already executing. At this point, suppose task C's node dies again. Thus we begin reconstruction under the same plan again. Task B's plan entry is duplicated since the previous entry hasn't been erased yet, and Task A's plan is repopulated. <img width="1180" height="1018" alt="image" src="https://github.com/user-attachments/assets/a6f8ab35-5522-4471-a6cc-6e1aeb12e59d" /> Here, notice that once task A completes, task B is essentially going to have two reconstruction attempts happening at the same time for the same plan_id. So let's suppose the earlier task B finishes. This will result in the entire plan being wiped, although the second task B is still executing. <img width="1634" height="1090" alt="Screenshot 2026-09-12 at 7 05 14 PM" src="https://github.com/user-attachments/assets/41682f09-9b04-4bd6-8c6e-3a64a813439f" /> Now if the second task B completes, it's deletion of the plan will result in a key error! Thus, this PR clears the dependency in the parent's plan upon child task submission instead of parent task completion. This means that when the first task B execution produced the dependency needed for task C, we would've cleared task B's plan there when task C was submitted instead of waiting for the executions to double up. Thus, avoiding the issue. ## Related issues ## Additional information --------- Signed-off-by: davik <[email protected]> Co-authored-by: davik <[email protected]>
… streaming executor (#66220) ## Description Note: By default the changes introduced in this PR are a no-op in Ray Data. Data lineage reconstruction is enabled only when the job turns off Ray Core lineage reconstruction via the JobConfig (`JobConfig(_disable_job_level_lineage_reconstruction=True)`, #65487) This PR wires the lineage tracker introduced in #65519 and developed to support fan-in and fan-out tasks in #65642, #66136. This is a part of a larger effort to introduce lineage reconstruction as a first class construct in Ray Data for application-level fault tolerance. A more detailed proposal can be found on this Ray Enhancement Proposal (ray-project/enhancements#74) A task serves at most one reconstruction plan here; batching several plans onto one seed re-execution is a follow-up PR. ## Additional Information I've broken down the changes introduced in this PR at a higher level below. ### Concepts This is a representation of block lineage and how it dictates which tasks need to be submitted for reconstruction. <img width="3045" height="1400" alt="lineage_diagram" src="https://github.com/user-attachments/assets/b7164ae8-369e-4b68-87c2-665fe253bcca" /> As seen in the sketch above, lineage for a fan-out pipeline results in certain blocks being pruned as they are not required to reconstruct the lost object(s). Conversely, fan-in pipelines require a number of ancestor blocks to be reconstructed. This has a direct impact on the number of re-submitted tasks with Data lineage reconstruction. At a high level, the sketch below shows that lineage reconstruction and regular Ray Data task execution run in tandem during a pipeline. The main ideas to grasp are the following: - Blocks that are emitted by reconstruction tasks that are NOT part of a lost block's lineage are pruned, or NOT propagated downstream - Blocks produced by reconstruction tasks that are part of a lost block's lineage are withheld in a separate data structure (while accounting for their resource usage). When all reconstruction blocks in a dependency set are ready, they are bundled and added to the operator outqueue for a child reconstruction task to consume <img width="1946" height="1626" alt="fan_in_fan_out_LR" src="https://github.com/user-attachments/assets/9f1ecda1-cb38-48f7-a1f4-08f4e840e9d6" /> #### Building the lineage graph while the dataset executes 1. A `LineageTracker` instance is declared for the DAG's streaming executor 2. An operator that reads directly from an `InputDataBuffer` is a 'seed' operator. Its input is durable and resubmittable (a `ReadTask`/`FileManifest`, or the data itself for `from_*`), so it retains that bundle in a map in case it ever needs to re-submit seed tasks. The tracker stores IDs, never actual `RefBundle`s. 3. **On task submission**:`MapOperator._submit_data_task` registers any task to be submitted with the `LineageTracker`, keeping track of whether it's a fresh task or a reconstruction task, and assigning it a logical Ray Data task ID - A producing task registers each block that is produced with the `LineageTracker`, via `_output_ready_callback`. Specifically, a tuple of (producing task logical ID, output index). A consuming task during submission time (3.) looks up the above dependencies to add edges in the lineage graph 5. **On task completion**: The `LineageTracker` marks the task in the graph as complete. #### Triggering lineage reconstruction when any output block is lost 1. The callback `DataOpTask.on_data_ready` catches an `ObjectLostError`, and triggers data lineage reconstruction 2. The `LineageTracker` traces the lost object's lineage, back to its seed task, and opens a reconstruction plan for it (or folds to an existing plan, if already open) 3. The streaming executor aborts the lost task so its operator releases resources, these will be requested again by the triggered reconstruction tasks 4. The streaming executor also clears the completion state for the DAG (if necessary), and re-submits the seed task. #### Managing reconstructed blocks 1. As each reconstruction task emits blocks, check the reuse status of each block. `NEW` flows downstream as usual, `PRUNED`/`UNRELATED` is dropped these are not required to reconstruct lost objects, and `REUSED` is withheld so that it can be passed along to following reconstruction tasks 2. For a fan-in, the withheld objects must be released together, so that a downstream reconstruction task can accept inputs exactly as in its original attempt (maintaining the same order of blocks) ### Known Limitations in Current Implementation - No batching of seed tasks (if multiple reconstruction plans can be served by a single seed task). This is explicitly addressed in a follow up PR to enable batching of reconstruction plans. - Blocks lost after they're handed to an iterator (`iter_batches`, `iter_rows`, `take`, `take_all`) aren't reconstructed. This is going to be addressed as part of a follow up effort to integrate external consumers (e.g. Ray Train) with Data FT - No support for DAGs with shuffles. Lineage reconstruction for pipelines with `AllToAllOperator` / shuffles in the DAG needs to be scoped. We will work on this in the future. --------- Signed-off-by: Ayush Kumar <[email protected]> Signed-off-by: Ayush Kumar <[email protected]>
…age reconstruction (#67519) ## Description Adds a manual release test, `image_embedding_from_uris_fake_gpu_lineage_reconstruction_chaos`, that exercises Ray Data lineage reconstruction under node loss and checks that the output is still exactly right. The driver starts with `JobConfig(_disable_job_level_lineage_reconstruction=True)`, so lost objects are rebuilt by Ray Data rather than Ray Core. A `RayletKiller` then kills worker raylets mid-run. It replaces `EC2InstanceTerminatorWithGracePeriod`, which drains a node before stopping it, so no objects are lost and reconstruction never runs. Changes to `image_embedding_from_uris/main.py`: - `--lineage-reconstruction` starts the driver with the job config above. With `--chaos`, the run counts calls to `LineageTracker.register_task_failed` that resubmit seed tasks. It fails if that count is 0, so a run where chaos never lost a needed object can't pass silently. The count is written to `result.json` as `lineage_reconstructions`. - `--fake-gpu` swaps in `FakeEmbedPatches`, which sleeps for the measured T4 inference time, so the test runs on 20 m5.2xlarge nodes that advertise a logical `GPU: 1` (`fake_gpu_small_cluster_compute.yaml`) instead of 100 g4dn nodes. Lineage reconstruction doesn't depend on real GPUs. - `--verify-output` runs the new `verify_output.py` against the sink after the write. - `create_metadata` adds a dense `row_serial` taken from the source order, so a re-executed task reproduces the same values. - `RAY_DATA_WRITE_PATH` optionally overrides the sink, which makes manual reruns of the verifier easier. `verify_output.py` reads the sink with pyarrow, not Ray Data, so a Ray Data bug can't hide itself. `(row_serial, patch_x, patch_y)` is a primary key and the full expected key set is known up front (69,000 images × 36 patches = 2,484,000 rows). The script checks: - completeness (dropped rows) - uniqueness (rows from over-reconstruction) - that every image produced its full patch set - that `row_serial` agrees with the metadata next to it, which catches a reconstructed block carrying the wrong rows It can also be run on its own, and `--sample-embeddings N` spot-checks embedding values. All new flags default to off, so the existing `image_embedding_from_uris_fixed_size` test is unchanged. The one shared change is the chaos killer used by `--chaos`, which only this new test passes. ## Related issues Related to the Ray Data lineage reconstruction series (#66136, #66990). Not a duplicate: I searched open PRs for "lineage reconstruction release test" and found no other PR adding a release test for Data lineage reconstruction. #66845 adds metrics and #66990 adds batching; neither touches release tests. ## Additional information **Testing** - `black --check` on `main.py` and `verify_output.py`: passes. - End-to-end run on a 20-node fake-GPU Anyscale workspace: <TODO: result, lineage_reconstructions count, verify_output summary> **AI assistance**: I wrote this with help from Claude Code, then reviewed every changed line myself. --------- Signed-off-by: Ayush Kumar <[email protected]>


Description
Note: This PR is a no-op and simply adds additional functionality to the Ray Data lineage tracking framework to support fan-out tasks.
This PR builds on top of #65642 to support pipelines with fan-ins on the lineage tracking. Here we define fan-in operators as operators whose tasks can take input blocks from more than one upstream operator tasks.
At a high level, we extend the plan concept discussed in #65642 via the following steps:
As discussed before, the steps for constructing the plan itself is as follows:
The main extension for supporting fan-ins is: As we walk up the graph when creating the plan, we must ensure that we visit all parents instead of assuming only a single parent. This will allow us to create plans that support fan-in operators.
Bug fix
Another change we've added to the lineage tracker on this PR is to address the issue mentioned in #65642 (comment). When we submit a reconstruction task, we now remove the submitted task from the set of children pending dependencies on the parent's plan instead of simply removing the plan when the parent task completes. This is necessary because it's possible for a reconstruction task to still be executing when another reconstruction attempt that needs to re-execute the same task is triggered. Consider the following scenario that was possible prior to this PR:
At this point, suppose task C's node dies again. Thus we begin reconstruction under the same plan again. Task B's plan entry is duplicated since the previous entry hasn't been erased yet, and Task A's plan is repopulated.
Here, notice that once task A completes, task B is essentially going to have two reconstruction attempts happening at the same time for the same plan_id. So let's suppose the earlier task B finishes. This will result in the entire plan being wiped, although the second task B is still executing.
Now if the second task B completes, it's deletion of the plan will result in a key error!
Thus, this PR clears the dependency in the parent's plan upon child task submission instead of parent task completion. This means that when the first task B execution produced the dependency needed for task C, we would've cleared task B's plan there when task C was submitted instead of waiting for the executions to double up. Thus, avoiding the issue.
Related issues
Additional information