Repository navigation
[Data] Trigger Data lineage reconstruction on RayActorError and RayTaskError - #67885
ayushk7102 wants to merge 1 commit into
Conversation
…kError Signed-off-by: Ayush Kumar <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request extends lineage reconstruction in Ray Data to recover from tasks that fail due to actor deaths (i.e., RayActorError wrapped in RayTaskError) in addition to standard ObjectLostErrors. It introduces the is_data_lineage_recoverable_error helper function, updates the streaming executor and physical operators to handle these recoverable errors, and adapts LineageReconstructionError to safely wrap general exceptions. Comprehensive unit tests have been added to validate these changes. I have no feedback to provide as there are no review comments.
NightWing1998
left a comment
There was a problem hiding this comment.
from a high level perspective, shouldn't the operator spinning the "actor pool/actor" retry at the failed actor level?
in this case, is it not possible for list files to catch that a particular actor it spun died and retry the work for that actor rather than LR getting triggered resubmitting the entire ListFiles task?
also my understanding was that lineage reconstruction would get triggered in cases when an input object is lost to rebuild the lost objects vs here it feels like we are substituting retries of a failed actor with lineage reconstruction.
sampan-s-nayak
left a comment
There was a problem hiding this comment.
also I agree with @NightWing1998 comment. we can modify the list files task to handle fault tolerance internally or make it return a lineage reconstructable exception (we can consider introducing a new dedicated exception type for this but I dont really like this idea)
| """ | ||
| if isinstance(error, ObjectLostError): | ||
| return True | ||
| return isinstance(error, RayTaskError) and isinstance(error, RayActorError) |
There was a problem hiding this comment.
we should not trigger lineage reconstruction for TaskErrors right? this could end up behaving as a retry mechanism instead of a FT mechanism for node deaths and object losses.
There was a problem hiding this comment.
also ActorUnavailableError is retried by ray core so we should exclude it from lineage reconstruction
| remaining_output_budget[state] - bytes_read, 0 | ||
| ) | ||
| except ObjectLostError as e: | ||
| except (ObjectLostError, RayActorError) as e: |
There was a problem hiding this comment.
nit: lets accept all exceptions here and if its not lineage reconstructable we can record it as an errored block. this was is_data_lineage_recoverable_error() will become the central check for lineage recoverable error types.
|
Changed the approach given feedback. We will now rely on #67988, with Ray Core to handle the restarts/retries for |
…s in listing order (#67988) ## Summary This PR turns on Ray Core restarts and task retries for `FooterReaderActor`, so a footer-reader process or node death no longer fails the Datasource v2 (DSv2) Parquet `ListFiles` task. Retries are only exactly-once if `read_footers` yields the same file at each position on every attempt, so it now always yields in listing order. Fixes #67886, an issue that on a `FooterReaderActor` death in the ListFiles task, datasets would simply fail, which made file listing not fault tolerant. Initially, I wanted to solve this problem by [triggering data lineage reconstruction on these errors](#67885), but we would have to expand the errors we trigger LR for. Also this would re-submit the listing task from the start, and would substitute actor-level retries with block reconstruction. A good Ray/Ray-Data pattern is that the owner of the actor pool should handle its failures. ## Before - `FooterReaderActor` used Core defaults: no restarts and no task retries. If a `FooterReader` died mid-listing, `ListFiles` raised `RayTaskError(ActorDiedError)` (process death) or `RayTaskError(ActorUnavailableError)` (node death), and the dataset failed. - `read_footers` yielded footers in completion order (`as_completed`) unless `preserve_order=True`. That made its output depend on IO timing, so enabling Core retries alone would be wrong. Core matches a retried streaming generator's items to the first attempt's by position (`ObjectRefStream::InsertToStream` drops an index below the consumer's cursor). A retry that finishes footers in a different order would then silently drop some files and duplicate others, and the row count would still look right. With the old ordering, a standalone repro (an actor with Core retries, SIGKILLed after delivering 6 of 20 files) dropped and duplicated 3–6 files in 10/10 trials with `preserve_order=False`, and 0/10 with `preserve_order=True`. ## After - `FooterReaderActor = ray.remote(max_restarts=-1, max_task_retries=-1)(FooterReader)`. A dead actor restarts, and its in-flight `read_footers` calls are retried. Python exceptions such as IO errors are still not retried and fail as before. - `read_footers` always yields in `files` order. The `preserve_order` argument and the `as_completed` branch are removed, along with the now-unused plumbing in `FooterFileIndexer._process_file_infos` / `_read_footers`. The public `list_files*` signatures are unchanged because the `FileIndexer` interface requires them. - This follows the existing Ray Data pattern: `ActorPoolMapOperator` actors use `max_restarts=-1, max_task_retries=-1` with streaming `submit`, and work done concurrently inside one call is always put back in input order (async UDFs in `plan_udf_map_op.py`, `ReadFiles` in `datasource_v2/common/file_reader.py`), regardless of `preserve_order`. - User-facing `DataContext.execution_options.preserve_order` is unchanged everywhere else, including path discovery in `NonSamplingFileIndexer`, operator output queues, `streaming_split` and union. ```mermaid flowchart TD subgraph Before subgraph BS[Subsystem: IO] subgraph BC[Component: DSv2 Parquet listing / ListFiles task] B1[FooterFileIndexer._read_footers] --> B2["FooterReaderActor<br/>no restarts, no task retries"] B2 --> B3["read_footers<br/>completion order unless preserve_order"] B2 -. actor dies .-> B4[ListFiles fails, dataset fails] end end end subgraph After subgraph AS[Subsystem: IO] subgraph AC[Component: DSv2 Parquet listing / ListFiles task] A1[FooterFileIndexer._read_footers] --> A2["FooterReaderActor<br/>max_restarts=-1, max_task_retries=-1"] A2 --> A3["read_footers<br/>always listing order"] A2 -. actor dies .-> A4[Core restarts actor and retries call, exactly-once] end end end Before ~~~ After classDef removed fill:#ffcdd2,stroke:#c62828,color:#000 classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 class B4 removed class A2,A3 changed class A4 added ``` ## Benchmarks to measure perf overhead **Summary:** On realistic workloads, yielding footers in listing order costs nothing measurable on full reads, batch inference or total job time. The one consistent cost is a few hundred milliseconds per read when a `limit` is pushed down into listing: +0.38s at the default footer batch size, levelling off at about +0.7s for larger batch sizes. The cost doesn't grow with job length. ### Why the cost is capped `FooterFileIndexer._read_footers` already drains footer batches in FIFO order (10 files per batch by default), and each batch only drains once its slowest footer has landed. This PR only changes when files *inside* a batch are released. A file can now wait for an earlier, slower footer in the same batch, but every batch still drains at the same time as before. So each file is delayed by at most one batch's slowest-footer time, and the delay doesn't carry over to later batches. The cost shows up when listing stops early (a pushed-down `limit`) or when the dataset is a single batch. ### Setup - Release tests were run unmodified, with their release config's cluster, data and env vars, over 3 paired rounds (master and PR concurrently). Footer latency comes from S3, with no injected delays. ### Release tests (default settings) | Release test | Cluster | Master (mean of 3) | PR (mean of 3) | Δ | |---|---|---|---|---| | `read_parquet_fixed_size` | 4× m5.8xlarge | 134.7s | 134.4s | −0.2% (noise) | | `read_large_parquet_fixed_size` | 4× m5.8xlarge | 530.3s | 530.5s | 0.0% | | `image_classification_from_parquet_fixed_size` | 10× g4dn.2xlarge | 209.0s | 208.1s | −0.4% (noise) | | `training_ingest_benchmark` (`s3_parquet_cpu`), job total | 1× r8i.16xlarge | 891.3s | 890.0s | −0.1% | | ↳ per `limit(1024)` iteration (12 configs) | | 12.90s | 13.28s | **+0.38s (+2.9%)** | ### Footer batch size sweep (`training_ingest_benchmark`, `RAY_DATA_PARQUET_FOOTER_BATCH_SIZE`) | Footer batch size | `limit(1024)` iteration Δ (~12.8s) | Configs slower on PR | `limit(8192)` iteration Δ (~60s) | Job total Δ (~15 min) | |---|---|---|---|---| | 10 (default) | +0.38s (+2.9%) | 9/12 | noise | −0.1% | | 30 | +0.55s (+4.3%) | 11/12 | noise | +1.1% | | 100 | +0.71s (+5.6%) | 11/12 | +1.2% | +2.0% | | 300 | +0.68s (+5.4%) | 12/12 | noise | +1.0% | ### Constructed worst case (for scale, not representative) Ten files, a single footer batch: the first file in listing order has a slow footer (150k tiny row groups, pruned by the filter), followed by nine 144 MB compacted files with heavy `map_batches` work. One node, default settings. | | Master | PR | Δ | |---|---|---|---| | Time to first batch | 13.1s | 21.3s | +8s | | End to end | 31.4s | 39.0s | +7.5s (+24%) | ### Findings 1. **No measurable cost on full reads or batch inference.** All release-test deltas are within run-to-run noise. 2. **Pushed-down `limit` pays a small fixed cost per read.** Master stops listing on whichever footers land first, while this PR waits for the first files in listing order. That's +0.38s per `limit(1024)` read at the default batch size. It's visible on 12s iterations and lost in noise on 60s ones. 3. **Larger footer batches raise that cost, but it levels off at about 0.7s.** A bigger batch gives master more fast footers to stop on, until the batch holds more files than the limit needs. Total job time stays within about 2% at every batch size tested. 4. **Large regressions need a contrived layout.** A slow-footer file at the head of a single-batch dataset with heavy downstream work costs about one slow-footer latency (+24% on a ~30s job). That cost shrinks as the dataset spans more batches. 5. **In exchange,** footer-reader actor deaths no longer fail the dataset, and the files a pushed-down `limit` reads no longer depend on IO timing. ## Subsystems IO (`_internal/datasource_v2/formats/parquet/`) ## Testing - New `test_footer_chunking.py::test_read_footers_actor_returns_all_file_chunks_after_actor_death`. It calls `read_footers` on a real `FooterReaderActor` with `_generator_backpressure_num_objects=1`, so the actor can run at most one result ahead of the caller. `test_generators.py::test_streaming_generator_actor_restarted_before_first_completion` uses the same option for the same reason. The test SIGKILLs the actor after the caller has consumed the first result, keeps reading the same generator, and asserts that every file arrives once in listing order and that the row-group rows sum to all 1200 rows. The last result can only come from the retried call, and the retry was logged in 3/3 runs. - With `max_task_retries=0` (restarts still on), the test fails with `ActorUnavailableError`. - With `as_completed` restored in `read_footers`, it failed in 2 of 3 runs, because local completion order is random. The deterministic check for ordering is `test_footer_reader.py::test_yields_in_listing_order`, which yields under reversed completion order without Ray. - `test_parquet_datasource_v2.py`: the fake actor no longer takes `preserve_order`, and `test_footer_indexer_forwards_preserve_order_to_footer_reads` is removed because the plumbing it checked no longer exists. `test_footer_indexer_preserves_listing_order_across_batches` still checks that the driver drains batches in order. - `conda run -n ray_env pytest python/ray/data/tests/datasource_v2/test_footer_chunking.py python/ray/data/tests/datasource_v2/test_footer_reader.py python/ray/data/tests/unit/datasource_v2/`: 841 passed, 93 skipped. - `conda run -n ray_env pytest python/ray/data/tests/datasource/test_read_parquet_v2.py`: passes except `test_read_parquet_v2_retries_transient_filesystem_errors`, which fails identically on unmodified master locally (`ModuleNotFoundError: No module named 'test_read_parquet_v2'` when workers unpickle the test's filesystem handler). Not related to this change. - `pre-commit run` on the changed files: passes. ## Notes - Not a duplicate: searched open PRs for `FooterReader` and footer-reader actor retries. The only related one is #67885 (mine), which this replaces. - AI assistance (Claude Code) was used to investigate, implement and benchmark this change. I reviewed every changed line and ran the tests above. --------- Signed-off-by: Ayush Kumar <[email protected]>
…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]>
Summary
Ray Data lineage reconstruction now recovers a task whose body failed because an actor it called died, not just a task whose output object was lost. The motivating case is a parquet datasource V2 read whose
FooterReaderactor dies whileListFilesis running. More info in this issue: #67886For the above
ListFilesissue, fixing it with this PR depends on #67882. Without it, anActorDiedErrorraised inside a map task reaches the driver asUnserializableExceptionand can't be matched.Before
When a lineage-tracked task fails, the error decides whether Ray Data reconstructs it:
ObjectLostErrorRayTaskError(ActorDiedError)(the task called an actor whose process died)RayTaskError(ActorUnavailableError)(the task called an actor whose node died)RayActorError(the actor running the task died)Ray Core doesn't retry the two
RayTaskError(...)cases either, because onlyRaySystemErroris in Data'sretry_exceptions. So a task that failed only because an actor it depends on died can't be recovered, even when its seed input is retained.After
ObjectLostErrorRayTaskError(ActorDiedError)RayTaskError(ActorUnavailableError)RayActorErroris_data_lineage_recoverable_errorinlineage_reconstruction_mixin.pyencodes the table: anObjectLostError, or aRayTaskErrorthat is also aRayActorError.ActorUnavailableErroris included because the task body has already raised, so nothing is left to wait for.DataOpTask.on_data_readyandprocess_completed_tasksuse it to route matching errors into_reconstruct_lost_object.LineageReconstructionErrorcan wrap an error without object fields, so a failed reconstruction of an actor error is reported instead of raisingAttributeError.Subsystems
Execution (
interfaces/physical_operator.py,operators/lineage_reconstruction_mixin.py,streaming_executor_state.py).ray/data/exceptions.pyhas a small ripple change soLineageReconstructionErroraccepts errors without object fields.Testing
pytest python/ray/data/tests/test_lineage_reconstruction.py: 38 passed. New tests:test_is_data_lineage_recoverable_error(lost object, nestedActorDiedErrorandActorUnavailableError, bareActorDiedError, nestedValueError).test_actor_died_in_task_raises_only_when_lineage_tracked.test_reconstruction_error_wraps_actor_error.FooterReaderprocess mid-listing: 1 reconstruction,ListFilesran twice, all 24576 rows exactly once.FooterReadermid-listing: 2 reconstructions,ListFilesran 3 times, all rows exactly once. The first rerun placed a newFooterReaderon the killed node before the GCS marked it dead, and the second reconstruction recovered from that.Known limitation (follow-up)
A rerun of the target task skips outputs already emitted by position.
FooterReader.read_footersyields footers in completion order within a batch, so aListFilesrerun can order its output differently. If manifests were already emitted before the failure, this could drop or duplicate files. It isn't ruled out by the runs above. The follow-up is to make footer reads ordered whenever lineage reconstruction is on.Notes
is_data_lineage_recoverable_errorand forRayActorErrorlineage reconstruction and found none.