Repository navigation
[Data] (Data Fault Tolerance 4/n) Integrate data lineage tracker with streaming executor - #66220
Conversation
…t lineage Wires the lineage tracker into the streaming executor so a lost task output is reconstructed from its lineage instead of failing the dataset. An `ObjectLostError` on a tracked task walks that task's ancestry back to its seed tasks and re-injects their retained inputs; re-produced outputs are classified per plan as they are generated, so pruned ones are dropped rather than re-emitted and the output row set stays exact. Opt-in behind `DataContext.enable_seed_input_lineage_recovery` (default off), so this is a no-op unless the flag is set. A task serves at most one reconstruction plan here; batching several plans onto one seed re-execution is a follow-up. Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
…g IDs Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
…n state Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
4f6d837 to
742cfa9
Compare
Signed-off-by: Ayush Kumar <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces experimental object-loss lineage recovery for Ray Data, integrating a new LineageTracker to record task lineage and coordinate task reconstruction plans upon encountering ObjectLostError. The changes span the streaming executor, physical operators, and metadata fetchers, and are accompanied by a comprehensive suite of integration tests. The review comments identify three critical issues in the recovery logic: a potential deadlock in _clear_downstream_completion_state on multi-input operators due to blindly resetting input completion states, a potential deadlock in fan-out scenarios where parent block outputs are prematurely popped from the held reconstruction dictionary, and a potential AttributeError when calling stamp_seed_reinjection on non-map seed operators.
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Kunchd
left a comment
There was a problem hiding this comment.
Thanks for the followup PR! I left some clarifying questions for how the tracker fits into ray data. The logic for how the lineage tracker is used looks good, but we definitely should have another Data member review the actual integration itself to make sure we're invoking the lineage tracker registrations at all the necessary locations.
| Record which task produced a block, so that whichever task later | ||
| consumes it can declare the dependency. |
There was a problem hiding this comment.
| Record which task produced a block, so that whichever task later | |
| consumes it can declare the dependency. | |
| Record which task produced a block, so that whichever task later | |
| consumes it can fetch the dependency easily with the block_id. |
| the executor thread, where an exception tears down the whole dataset. | ||
| """ | ||
| if not isinstance(task, DataOpTask) or task.data_task_id is None: | ||
| logger.info( |
There was a problem hiding this comment.
Probably want to log this at warning level.
| ) | ||
| return False | ||
|
|
||
| # A reconstruction that re-fails stays in the plan it serves; a fresh failure |
There was a problem hiding this comment.
| # A reconstruction that re-fails stays in the plan it serves; a fresh failure | |
| # A retry of a failed reconstruction attempt stays in the plan it serves; a fresh failure |
| "registered with the lineage graph; cannot recover.", | ||
| task.data_task_id, | ||
| state.op.name, | ||
| ) |
There was a problem hiding this comment.
nit: instead of logging the error here, we should add this message as part of the error message we throw and propagate it up so the user layer can see reconstruction was triggered but failed. This will help them help us by providing better failed traces.
There was a problem hiding this comment.
Adding a LineageReconstructionError which will represent any errors caught during lineage reconstruction. This will subclass ObjectLostError and will carry the original task failure reason as well, so that we can surface more information about the failed task and reconstruction attempt
|
|
||
| seed_task_ids = sorted(traced_seed_ids) | ||
|
|
||
| if not seed_task_ids: |
There was a problem hiding this comment.
In what cases is the seed_task_ids empty? is this expected?
There was a problem hiding this comment.
Traced the code here and I realize this is not possible. The only way we can come across empty list of seed tasks if the sed task was not registered, but this is not possible as we would have raised a ValueError above when we start the walk to the seed op.
| "[lineage-recovery] No retained input for seed task %s; cannot " | ||
| "recover.", | ||
| seed_id, | ||
| ) |
There was a problem hiding this comment.
Same here, please propagate this as error message upwards.
There was a problem hiding this comment.
Removing this as it's not possible to reach this state as mentioned above
| InputDataBuffer, | ||
| ) | ||
|
|
||
| return any(isinstance(dep, InputDataBuffer) for dep in self.input_dependencies) |
There was a problem hiding this comment.
Why any() here? Is it possible for only some of the input dependencies to but InputDataBuffer?
There was a problem hiding this comment.
Good catch. Since map_operator is a OneToOneOperator it will only have a single input dependency and this can become
return isinstance(self.input_dependency, InputDataBuffer)
| Addressed to the consumer that owns the child rather than broadcast to every | ||
| output dependency. No adjacent consumer owning it means some non-map operator | ||
| sits between them: there is nobody to carry the identity to, and the bundle is | ||
| submitted as ordinary work. Warned about rather than raised: the rows still | ||
| flow. |
There was a problem hiding this comment.
nit: Could we rephrase this, I couldn't quite understand what it was saying.
There was a problem hiding this comment.
Basically, we need to store a mapping between the input bundle and the (child_task_ID, plan_ID) so that the child operator can identify which task ID to assign the reconstruction task, and what plan it belongs to.
Rephrased it as follows:
"""Store a mapping of the input bundle to the (child task, plan ID) it belongs to.
The bundle travels downstream through the normal output queue, and the child op
needs to the original child task ID and plan ID for scheduling it as a reconstruction task.
When that operator submits a task for these blocks, it reuses the child's
original id, so the lineage tracker sees the plan's re-execution rather than
a new task.
""""
| # set is in hand synchronously -- see `_release_reconstruction_children`. | ||
| self._reconstruction_outputs: Dict[ | ||
| PlanId, Dict[ParentBlockOutput, RefBundle] | ||
| ] = {} |
There was a problem hiding this comment.
We only keep track of the task submission at the map_operator level. Are all the operator we want to target in our initial pass (streaming execution) an implementation of the map_operator?
There was a problem hiding this comment.
Discussed offline, for our v1, we only want to support DAGs which are composed with non-shuffle operators. map_operator should cover all operator types except Aggregate, Join, Count, Mix, Union and a few others which we want to address with shuffle work
There was a problem hiding this comment.
Also, in the interim, we are going to explicitly disable data LR on DAGs where these operators are found.
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
…for consistency Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
…e task ID Signed-off-by: Ayush Kumar <[email protected]>
…into data_lineage_integration
Signed-off-by: Ayush Kumar <[email protected]>
…ued_block() on lineage tracker Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
| seed_op.name, | ||
| seed_input.size_bytes(), | ||
| reconstruction_plan_id, | ||
| ) |
There was a problem hiding this comment.
Reconstruction retries have no bound
High Severity
_reconstruct_lost_object re-injects the stored seed RefBundle on every ObjectLostError with no attempt limit. For from_* and materialized sources the seed input is the data, so a lost source object is re-submitted unchanged, fails again, and the executor resubmits forever.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 8aaddd5. Configure here.
| except LineageReconstructionError as recon_error: | ||
| # In case lineage reconstruction fails, abort the task | ||
| task.mark_aborted(recon_error) | ||
| _record_errored_block(recon_error, state.op.name) |
There was a problem hiding this comment.
Fetcher loss skips reconstruction
Medium Severity
ObjectLostError from the threaded metadata fetcher is routed through _record_errored_block instead of _reconstruct_lost_object. The lost block is dropped and counted as an error, so lineage reconstruction never runs for objects that disappear after they are deferred.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 8aaddd5. Configure here.
Signed-off-by: Ayush Kumar <[email protected]>
…econstruction blocks Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
…ructionMixin for extensibility Signed-off-by: Ayush Kumar <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 4 total unresolved issues (including 3 from previous reviews).
Reviewed by Cursor Bugbot for commit 999d41a. Configure here.
…ch task node Signed-off-by: Ayush Kumar <[email protected]>
| lineage_tracker: "LineageTracker", | ||
| task_index: int, | ||
| inputs: RefBundle, | ||
| ) -> Tuple[LineageTaskId, Optional[ReconstructionPlanId], List[ParentBlockOutput]]: |
There was a problem hiding this comment.
Let's make this a dataclass
Signed-off-by: Ayush Kumar <[email protected]>
… Data lineage reconstruction (#66990) ## Description When several tracked tasks lose their output, each failure opens its own reconstruction plan. If those plans trace back to the same task, today each one re-injects the seed separately, so the read runs once per plan. So does every downstream task that the plan shared. That is a lot of redundant work during reconstruction. Let's say there are two different downstream objects that are lost independently, which result in two separate reconstruction plans A and B. Let's also say that both plans A and B trace back to the same seed task (say T). With the changes from this PR, we should now only re-submit the seed task T once for both plans. This "batching" can be done by noticing that the traced seed task for a plan is already queued for submission (but not submitted yet), and simply joining on to the same seed task. By updating the lineage tracking metadata, we can use the same seed to emit block outputs required for multiple different reconstruction plans at the same time. The `LineageTracker` API is unchanged. Batching is purely an optimization. If a plan can't be batched, behavior is exactly what it was before, with the task re-run for that plan. We can only batch reconstruction plans with a queued task because if it is submitted, it's likely that it is too late, and the required output block for the second plan has already been dropped due to being `OBJECT_PRUNED` at the time. **Limitations:** - Joining depends on timing. It only happens if the second failure is processed before the seed's re-execution is dispatched. ## Related issues Optimization on top of the Ray Data integration with lineage tracker API first started in #66220 ## Additional information ### Tests ``` conda run -n ray_env pytest python/ray/data/tests/test_lineage_reconstruction.py \ python/ray/data/tests/test_ref_bundle.py \ python/ray/data/tests/unit/test_lineage_tracker_linear.py \ python/ray/data/tests/unit/test_lineage_tracker_fan_out.py \ python/ray/data/tests/unit/test_lineage_tracker_fan_in.py -q 117 passed ``` New or updated tests in `test_lineage_reconstruction.py`: - `test_losses_before_the_seed_is_submitted_share_one_reconstruction_task`: two real losses through `_reconstruct_lost_object` re-inject the seed once, and the one run serves both plans, holding and releasing outputs correctly for each. - `test_joined_plans_sharing_a_child_release_it_once`: a child both plans need is released once, stamped with both plans, and runs once. - `test_shared_child_is_batched_until_it_is_submitted`: a plan joins a queued child, or re-runs it if the child was already submitted. - `test_seed_targeted_by_one_plan_and_reused_by_another`: one run serves a plan it is the target of and a plan it is an intermediate of. - `test_loss_after_the_seed_reconstruction_task_is_submitted_re_injects_the_seed`: a new plan due to a object loss after another plan's submission can no longer join it, and rather is re-submitted as a new plan --------- Signed-off-by: Ayush Kumar <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ng executor integration tests to prevent flakiness (#68049) ## Description This PR rewrites all of the integration tests for lineage reconstruction as well as some unit tests, to fix flakiness in the test suite. ### Why `test_lineage_reconstruction` was flaky in CI. This is because several tests simulated a lost block with a `lose_output` fixture that monkeypatched `DataOpTask.on_data_ready` to raise `ObjectLostError` on the Nth time the executor polled a given task. The problem is that the number of polls it takes to drain a task is non-deterministic. It depends on whether metadata is fetched on a background thread or inline, and on how fast tasks are submitted and finish. the task drained before the Nth poll, so the loss never fired and an assertion based on the number of reconstructions failed. ### Integration test changes Rather than relying on executor poll timing/task completion time, we now encode a failure into the data itself (i.e. a particular row will tell the UDF to mock a lost block). A `map_batches` UDF raises `ObjectLostError` when it sees a specific row, and the executor handles that exactly like a block lost with its node. The end-to-end tests then check that the loss actually happened, and every row comes back exactly once. They cover linear, fan-in, fan-out, multi-operator, actor pool and write pipelines, plus a block that's lost a second time while it's being reconstructed. ### Unit test changes I reworked all of the old lineage reconstruction unit tests that are specific to the integration with the streaming executor. The purely unit tests that don't need a Ray cluster moved to `tests/unit/test_lineage_reconstruction_executor.py`. No production code changes. ## Related issues Related to #66220 and #66990. ## Additional information I checked open PRs and nothing else rewrites these tests. #67366, #67885 and #68042 add tests to the same file, so whichever of us lands second will need to rebase. Testing: I ran the unit tests 30 times and the integration tests 6 times (3 with the threaded metadata fetcher, 3 with the inline one). Everything passed every time. --------- Signed-off-by: Ayush Kumar <[email protected]>
12/n stopped Ray Core from restarting actor-only actors. A dead actor is released and the sizer replaces it, so its lost work, and any blocks lost with a node, have to be rebuilt by Ray Data lineage reconstruction (#66220). This PR wires that into the actor-only backend. **Recovery routing** - On a lineage-tracked task, `RayActorError` (the actor died) now goes to lineage reconstruction, like `ObjectLostError`. That applies in both the default executor loop and the actor-only loop, through one shared `recover_or_count_lost_output` helper. `ActorUnavailableError` does not. - Deferred metadata-fetch failures go through the same routing. The fetcher now reports the failed task instead of its operator name. - The actor-only backend refuses to start when the job has Data reconstruction off (`JobConfig(_disable_job_level_lineage_reconstruction=True)` not set), because nothing else can recover a node loss. Plans #66220 can't reconstruct (split, union, mix, limit) still run, with reconstruction off for that dataset. **ResourceBank accounting** - During reconstruction, a re-made block is withheld until its child's whole input set is back. Withheld blocks are now charged to the producing actor, and also counted as withheld, so they can be told apart from output a consumer can drain. Release, a displaced copy, and `clear_internal_output_queue` each undo the charge. - A released input set goes into the output queue under the producing actor's key (`_output_add_kwargs`), not the task index. **Escape hatch for withheld-block wedges** - An actor is wedged when its pull budget is exhausted only because of blocks it is withholding. Nothing downstream can drain those blocks until the set is complete, so it would stall forever. - `relieve_withheld_wedges` runs before the existing output-limit walk. It gives a wedged actor room for what it withholds plus one block: 1. free object store on its node, reserved in the bank so no other grant counts it again; 2. then unused budget lent by other actors on the same node, whose caps go down by the same amount; 3. if that's not enough, it waits while those actors' full budgets would cover the rest once their outputs are consumed, and only oversubscribes beyond that. - Grants are kept on the actor and given back once its withheld outputs are released, or when it dies (lenders get their budget back). - The existing output-limit hatch now uses the same reservation and borrowing. It still grants its one-block bump immediately when there's no room. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: iamjustinhsu <[email protected]> Co-authored-by: sampan <[email protected]> Co-authored-by: Prasad Palkar <[email protected]>


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.
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:
Building the lineage graph while the dataset executes
LineageTrackerinstance is declared for the DAG's streaming executorInputDataBufferis a 'seed' operator. Its input is durable and resubmittable (aReadTask/FileManifest, or the data itself forfrom_*), so it retains that bundle in a map in case it ever needs to re-submit seed tasks. The tracker stores IDs, never actualRefBundles.MapOperator._submit_data_taskregisters any task to be submitted with theLineageTracker, keeping track of whether it's a fresh task or a reconstruction task, and assigning it a logical Ray Data task IDLineageTracker, 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 graphLineageTrackermarks the task in the graph as complete.Triggering lineage reconstruction when any output block is lost
DataOpTask.on_data_readycatches anObjectLostError, and triggers data lineage reconstructionLineageTrackertraces 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)Managing reconstructed blocks
NEWflows downstream as usual,PRUNED/UNRELATEDis dropped these are not required to reconstruct lost objects, andREUSEDiswithheld so that it can be passed along to following reconstruction tasks
Known Limitations in Current Implementation
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 FTAllToAllOperator/ shuffles in the DAG needs to be scoped. We will work on this in the future.