Repository navigation
[Data] DSv2 Reorg [3.5/6]: Let a listing task leave out read units a checkpoint already finished - #66398
Conversation
| execution_idx: Execution index used with ``shuffle_config`` to | ||
| derive a per-execution seed. | ||
| excluded_read_unit_ids: Ids of read units (see ``ReadUnit.id``) a | ||
| checkpoint already finished; they must not be listed. A file |
There was a problem hiding this comment.
Nice hook, the before/after table makes the resume win really clear! 🙌
One thing worth spelling out in this docstring: every id in excluded_read_unit_ids is skipped completely, so an id should only be passed when every row of that unit is already saved.
The easy mistake is to collect the ids stamped on the saved rows and pass them straight in. Then a row group with only some rows saved gets skipped whole, and its remaining rows never run, with no error.
Could we add a line like: "Only pass ids of units whose rows are all committed; partially finished units must not be included." That way whoever wires up checkpointing doesn't trip on it.
fbfb65a to
ddec369
Compare
…checkpoint already finished Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
… checkpointed Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
ddec369 to
a8d84c0
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces support for excluding already-finished read units (such as whole files or specific Parquet row groups) during the listing phase of a resumed job. This is achieved by passing "excluded_read_unit_ids" down to the file indexers and footer readers, allowing the system to skip processing completed work early and pack only the remaining tasks efficiently. The review feedback highlights opportunities to optimize performance by ensuring "excluded_read_unit_ids" is treated as a set or frozenset for O(1) lookups in both "FooterReader" and "FileIndexer", and suggests an early return in "FooterReader._read_and_chunk" when all row groups of a file are excluded.
| self.excluded_read_unit_ids: AbstractSet[str] = ( | ||
| excluded_read_unit_ids or frozenset() | ||
| ) |
There was a problem hiding this comment.
If excluded_read_unit_ids is passed as a list or other non-set iterable, lookup operations using in will be frozenset during initialization.
| self.excluded_read_unit_ids: AbstractSet[str] = ( | |
| excluded_read_unit_ids or frozenset() | |
| ) | |
| self.excluded_read_unit_ids: AbstractSet[str] = ( | |
| frozenset(excluded_read_unit_ids) if excluded_read_unit_ids else frozenset() | |
| ) |
| all_rg_indices = [ | ||
| i | ||
| for i in range(metadata.num_row_groups) | ||
| if _row_group_unit_id(path, i) not in self.excluded_read_unit_ids | ||
| ] | ||
| if len(all_rg_indices) < metadata.num_row_groups: | ||
| # Row groups a checkpoint already finished. Dropping them here, | ||
| # before the predicate split and before ``_read_footers`` counts | ||
| # rows toward a pushed-down limit, means a resumed job neither | ||
| # re-reads them nor stops listing early on their account. | ||
| fragment = fragment.subset(row_group_ids=all_rg_indices) |
There was a problem hiding this comment.
If all row groups of a file are excluded (i.e., all_rg_indices is empty), we can return an empty FileChunks immediately. This avoids redundant PyArrow operations, predicate pruning, negation checks, and coalescing.
| all_rg_indices = [ | |
| i | |
| for i in range(metadata.num_row_groups) | |
| if _row_group_unit_id(path, i) not in self.excluded_read_unit_ids | |
| ] | |
| if len(all_rg_indices) < metadata.num_row_groups: | |
| # Row groups a checkpoint already finished. Dropping them here, | |
| # before the predicate split and before ``_read_footers`` counts | |
| # rows toward a pushed-down limit, means a resumed job neither | |
| # re-reads them nor stops listing early on their account. | |
| fragment = fragment.subset(row_group_ids=all_rg_indices) | |
| all_rg_indices = [ | |
| i | |
| for i in range(metadata.num_row_groups) | |
| if _row_group_unit_id(path, i) not in self.excluded_read_unit_ids | |
| ] | |
| if not all_rg_indices: | |
| return FileChunks(path=path, size=size, row_groups=()) | |
| if len(all_rg_indices) < metadata.num_row_groups: | |
| # Row groups a checkpoint already finished. Dropping them here, | |
| # before the predicate split and before ``_read_footers`` counts | |
| # rows toward a pushed-down limit, means a resumed job neither | |
| # re-reads them nor stops listing early on their account. | |
| fragment = fragment.subset(row_group_ids=all_rg_indices) |
| if excluded_read_unit_ids: | ||
| # A whole file a checkpoint finished. Dropped here, before any | ||
| # metadata fetch, so a metadata-aware subclass never reads its footer. | ||
| file_infos = ( | ||
| fi for fi in file_infos if fi.path not in excluded_read_unit_ids | ||
| ) |
There was a problem hiding this comment.
If excluded_read_unit_ids is passed as a list or other non-set iterable, the membership check fi.path not in excluded_read_unit_ids will perform a linear scan
if excluded_read_unit_ids:
# A whole file a checkpoint finished. Dropped here, before any
# metadata fetch, so a metadata-aware subclass never reads its footer.
excluded_set = (
excluded_read_unit_ids
if isinstance(excluded_read_unit_ids, (set, frozenset))
else set(excluded_read_unit_ids)
)
file_infos = (
fi for fi in file_infos if fi.path not in excluded_set
)…frozenset where the listing task reads them Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
| if metadata.num_row_groups | ||
| else None | ||
| ) | ||
| all_rg_indices = [ |
There was a problem hiding this comment.
unprocessed_rg_ids
| # Row groups a checkpoint already finished. Dropping them here, | ||
| # before the predicate split and before ``_read_footers`` counts | ||
| # rows toward a pushed-down limit, means a resumed job neither | ||
| # re-reads them nor stops listing early on their account. |
There was a problem hiding this comment.
This comment needs to be clarified.
| # ``TaskContext.kwargs`` is untyped, so normalize here once: every lookup | ||
| # downstream (per file, per row group) then stays O(1) whatever was passed. | ||
| excluded_ids = ctx.kwargs.get(EXCLUDED_READ_UNIT_IDS_KWARG_NAME) | ||
| excluded_read_unit_ids = frozenset(excluded_ids) if excluded_ids else None |
There was a problem hiding this comment.
Let's clarify in the comments why the excluded read units need to be passed in dynamically.
It's because we checkpoint on every write task which results in a high volume of checkpoint files, so has to be processed lazily.
…n why the excluded ids come through the task context Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
…checkpoint already finished (ray-project#66398) ## Description A resumed job knows which read units it already finished: the reader stamps every row with its `ReadUnit.id` (ray-project#66390), so a checkpoint of the committed rows names them. Today the only place that knowledge could be applied is the read task, after `ListFiles` has read every footer and the partitioner has packed every row group into tasks. That re-reads footers of finished files and leaves a resumed job with one near-empty task per touched file. This PR gives `ListFiles` a single input, the set of finished read unit ids, and drops those units at the earliest point that knows about them. Nothing in this PR performs checkpointing; it is the hook the checkpoint stack (ray-project#65887) plugs into. ### What changes 1. **`read_units.py`.** `EXCLUDED_READ_UNIT_IDS_KWARG_NAME`, the `TaskContext.kwargs` key a resumed job sets on the `ListFiles` operator (`MapOperator.create(map_task_kwargs=...)`). Module docstring says how the ids flow. 2. **`listing/listing_utils.py`.** `list_files_for_each_block` reads the set from `ctx.kwargs` and passes it to `FileIndexer.list_files`. 3. **`listing/file_indexer.py`.** `list_files` and `_iter_file_infos_for_list` take `excluded_read_unit_ids`. A file whose path is in the set is dropped right after path discovery, before any metadata fetch, so a footer-based indexer never opens it. Ids that name nothing are ignored. 4. **`listing/footer_file_indexer.py`.** Forwards the set to the `FooterReader` actors after the whole-file drop. 5. **`listing/footer_reader.py`.** `_read_and_chunk` removes row groups named `<path>#rg<N>` before the predicate split and before rows are counted toward a pushed-down limit, so a resumed job neither re-reads them nor stops listing early on their account. 6. **`chunkers/parquet_file_chunking_utils.py`.** `_row_group_unit_id(path, rg)` is the one place that spells the row-group id; the chunker and the footer reader both call it. 7. **Tests.** `tests/unit/datasource_v2/test_read_units.py` (new): ids the reader reports round-trip through the footer reader; unknown ids are ignored and a finished file drops; exclusion happens before predicate and limit accounting; the plain indexer skips whole files by path; the footer indexer skips whole files before any footer read and forwards row-group ids; the listing task forwards the set from `ctx.kwargs`; excluding at listing time packs only the remaining work. One mock in `test_parquet_datasource_v2.py` accepts the new keyword. ### Before / after: resuming at 90% done 20 files of 4 row groups each, bins sized to one file. A resume with every row group finished except the last of the first 8 files (from `test_excluding_units_at_listing_time_packs_only_remaining_work`): | | footers read | read tasks | | --- | --- | --- | | Exclusion in the read task (today's only option) | 20 | 20, of which 12 empty and 8 at a quarter of a file | | Exclusion in listing (this PR) | 8 | 2 full bins | ### Behavior With no excluded ids nothing changes: `excluded_read_unit_ids` defaults to `None` at every layer and the footer reader's row-group range is the same `range(metadata.num_row_groups)` as before. ## Additional information Not a duplicate: ray-project#65887 (checkpoint stack, `[3/4]`) drops finished files and row groups with its own per-file compact block threaded through the same indexer and reader; this PR is the general hook, keyed on `ReadUnit.id`, that work can call instead. No other open PR touches listing-time exclusion. Checks run locally from this branch (macOS, `~/ray/.venv`): ``` pytest -q tests/unit/datasource_v2 # 140 passed ``` `ruff`, `black` and `pydoclint` at the pre-commit pins are clean; `pyrefly` via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to the `[3/6]` head, none new. Written with Claude Code; I reviewed every changed line and ran the tests above. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Aarrya <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
…and partial row masks (#66733) Follow-up to 1/4 (#66732, merged). 3/4 (#66736) builds on this. ## Why are these changes needed? A resumed generated-ID job has to know what's already done, in terms the DSv2 read path understands: **read units** (files and Parquet row groups). This PR turns the committed generated IDs into exactly that, so the planner in 3/4 (#66736) can skip it: listing drops the done units, and a step after the read drops the done rows of partly done row groups. ## What changes - **`GeneratedIdColumnCheckpointManager.load_generated_id_checkpoint()`** returns a `GeneratedIdCheckpoint`, kept in Arrow so it stays small on the driver and cheap to send to tasks: - `done_unit_ids`: an Arrow string array. A file's path when every row group of the file is committed, otherwise `"<path>#rg<N>"` per committed row group. Ids come from DSv2's `_row_group_unit_id`, so they match what the listing hook `excluded_read_unit_ids` (#66398) expects. - `partial_masks`: an Arrow table, one row per row group with only some rows committed: `unit_id` and a boolean `partial_mask` indexed by `row_id`. These are small: only row groups in flight when a job stopped are partly done. - **Compaction:** committed IDs are grouped per file with Ray Data (`groupby(path_prefix, file_name).map_groups`) into one row per done or partly done read unit: `unit_id` plus `partial_mask` (null when done). A file whose row groups are all done is a single row with its path. Masks stay numpy end to end. Duplicate IDs, from rows written more than once, are counted once, so a partly done row group never looks done. - **Refactor:** `CheckpointManager.load_checkpoint` is split so the shared steps live in `_load_checkpoint_block`: clean pending checkpoints, list committed files only (#66387), read, preprocess, one block. The `id_column` path's behavior is unchanged. The generated-ID manager's `load_checkpoint` (the numpy array path) raises, because struct IDs can't go there. - The checkpoint read opts out of the generated ID column (from 1/4). - **CI:** `checkpoint/generated_id.py` joins `ci/lint/pyrefly-excluded-files.txt`. Its `pyarrow.compute` calls (`pc.struct_field` and friends) are generated at runtime, so pyrefly reports them as missing; other pyarrow-heavy checkpoint files (`checkpoint_filter.py`, `interfaces.py`) are excluded for the same reason. Nothing calls the new load yet; 3/4 does. ## Related issue number N/A. Not a duplicate (see 1/4). ## Checks - [x] I've signed off every commit (DCO). - [x] I've run pre-commit on all changed files: clean. The API-annotation check reports nothing unannotated. - [x] AI assistance (Claude Code) was used for the development of this PR. I, Abhishek Verma, am the human submitter signing off on it: I have reviewed every changed line, run the tests below locally, and can defend the change end-to-end. - Testing: - `pytest python/ray/data/tests/unit/test_generated_id_checkpoint.py`: 9 passed. Covers done vs. partial row groups, duplicates counted once, whole file named when all row groups are done, and compacted paths matching the source path exactly (bare file name, absolute path, and a backslash Windows-style path) and IDs outside a row group never marking it done. - `pytest python/ray/data/tests/test_checkpoint.py` (on current master): 92 passed, 1 failed (the same pre-existing local moto-S3 flake as 1/4). New: loading real checkpoint files with pending files ignored and the generated-ID config active during the load; empty checkpoint. - pyrefly (CI's file set and flags) on the changed files: 0 errors. API parameter coverage check: nothing newly undocumented. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Abhishek Verma <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…ng committed work at the source (#66736) Follow-up to 1/4 (#66732) and 2/4 (#66733), both merged. 4/4 (#66734) is an independent speed-up that lands last; this PR doesn't need it. ## Why are these changes needed? This switches the feature on. A resumed `generated_id_column` job now skips work it already committed, as early as possible. It doesn't run the actor-pool `CheckpointFilter` that the `id_column` path applies to every row. ## What changes - **Planner routing** (`planner.py`). Generated-ID jobs get: - `ListFiles` → `plan_list_files_op_with_done_read_units`: passes the checkpoint's done unit ids as `EXCLUDED_READ_UNIT_IDS_KWARG_NAME` (the hook from #66398). Fully committed files are never listed, and fully committed row groups are never read. - `ReadFiles` → `plan_read_files_op_with_done_rows`: the normal read followed by a `DropCommittedRows` step for row groups that were only partly committed. - Each row's generated ID names its file, row group and `row_id`, so the step looks up the row group's mask and drops rows where `mask[row_id]` is set. - The step fuses into the read task (`ReadFilesParquetV2->DropCommittedRows->...`), so no extra stage runs. - Thanks @AarryaSaraf for suggesting this over a new reader hook (the former 4/5, #66735, now closed). - The checkpoint's masks arrive as an Arrow table; each task indexes them once (`_partial_mask_lookup`) and reuses the lookup for every block. Masks stay numpy. - `Write` → the existing checkpoint two-phase commit. - The `id_column` path is unchanged. 1/4's interim write-only gate is removed. - **Listing accepts Arrow ids** (`listing_utils.py`): the checkpoint passes done unit ids as an Arrow array. Listing converts them to Python strings before building its lookup set; a set built straight from an Arrow array would hold Arrow values and never match. - **Loading:** `LoadCheckpointCallback` loads the checkpoint once when execution starts (`load_generated_id_checkpoint`, from 2/4). Both plan functions read it through task kwargs set lazily (`add_map_task_kwargs_fn`), because it isn't loaded at planning time. A crashed run's pending checkpoints are still cleaned up while planning, before the load. - **Runs that don't restore** (`CheckpointConfig._should_restore`, from #66563): after a successful run sets it to `False` (e.g. later training epochs), the planner plans only the checkpoint write, as for `id_column`, and `LoadCheckpointCallback` skips loading the generated-ID checkpoint, since no operator reads it. - **Validation:** plans whose sources aren't V2 Parquet reads (`ReadFiles` over a `ParquetScanner`) raise `InvalidCheckpointingConfig` with a pointer to `id_column`. This covers the V1 `Read` path and non-Parquet V2 scanners. - **Docs:** a "Checkpoint without an ID column" section in `doc/source/data/execution-configurations.md`. Note: like the `id_column` path's filter, `DropCommittedRows` runs after the read, so a `limit` pushed into the read counts rows before they're dropped. ## Related issue number N/A. Not a duplicate (see 1/4). Replaces my pre-reorg drafts #65886, #65887 and #65888. ## Checks - [x] I've signed off every commit (DCO). - [x] I've run pre-commit on all changed files: clean. `vale` (v3.17.1, as in CI) on the docs page: 0 errors, 0 warnings, 0 suggestions. - [x] AI assistance (Claude Code) was used for the development of this PR. I, Abhishek Verma, am the human submitter signing off on it: I have reviewed every changed line, run the tests below locally, and can defend the change end-to-end. - Testing: - `pytest python/ray/data/tests/unit/test_generated_id_checkpoint.py`: 15 passed. New: masked rows dropped per row group in a block mixing row groups and files; rows past a short mask kept; no matching mask means no change; mask lookup across table chunks. - `test_read_units.py`: listing skips done units whether the ids arrive as a set, an Arrow array, or a chunked array. The Arrow cases fail without the conversion. - With `_should_restore=False`, a run ignores the kept checkpoint, reads every row, never loads the checkpoint, and still writes checkpoints. I checked that this test fails without the callback fix. - On current master, `pytest python/ray/data/tests/test_checkpoint.py python/ray/data/tests/test_data_iterator_checkpointer.py python/ray/data/tests/unit/test_generated_id_checkpoint.py python/ray/data/tests/unit/datasource_v2`: 299 passed, 1 failed. The failure, `test_skip_checkpoint_flag[s3]`, is a pre-existing local moto-S3 flake that also fails on unmodified master. - New end-to-end tests in `python/ray/data/tests/test_checkpoint.py`: - Crash partway, then rerun: no missing rows, and the checkpoint is deleted on success. - Resume skips a fully committed file, a committed row group, and the committed rows of a partly committed row group, and reads a never-seen file in full. The output is exactly the uncommitted rows. I checked that this test fails with `DropCommittedRows` disabled. - A rerun after a full success writes nothing. - The plan has no `CheckpointFilter` op, and `DropCommittedRows` is fused into the read. - Non-Parquet and V1 inputs are rejected. - `pytest python/ray/data/tests/unit/test_generated_id_checkpoint.py`: 15 passed. New: masked rows dropped per row group in a block mixing row groups and files; rows past a short mask kept; no matching mask means no change; mask lookup across table chunks. - Block sizing: a `generated_id_column` read produces the same number of blocks per task as a plain read (`DropCommittedRows` keeps `target_max_block_size`). - `test_read_units.py`: listing skips done units whether the ids arrive as a set, an Arrow array, or a chunked array. The Arrow cases fail without the conversion. - With `_should_restore=False`, a run ignores the kept checkpoint, reads every row, never loads the checkpoint, and still writes checkpoints. I checked that this test fails without the callback fix. - On current master, `pytest python/ray/data/tests/test_checkpoint.py python/ray/data/tests/test_data_iterator_checkpointer.py python/ray/data/tests/unit/test_generated_id_checkpoint.py python/ray/data/tests/unit/datasource_v2`: 299 passed, 1 failed. The failure, `test_skip_checkpoint_flag[s3]`, is a pre-existing local moto-S3 flake that also fails on unmodified master. - `pytest python/ray/data/tests/unit python/ray/data/tests/datasource_v2`: 1500 passed. - Five modules didn't collect locally for missing optional dependencies (torch, pyiceberg, freezegun). - Two failures in `test_dynamic_work_queue.py`, which also fail on unmodified master. - **Together with 4/4** (local combined branch): 237 DSv2/unit and 38 checkpoint tests passed. In a manual resume run (4 files × 4 row groups, 16 write tasks), I deleted 6 committed checkpoint files and the rerun wrote **exactly those 6,000 rows**. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Abhishek Verma <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Description
A resumed job knows which read units it already finished: the reader stamps
every row with its
ReadUnit.id(#66390), so a checkpoint of the committedrows names them. Today the only place that knowledge could be applied is the
read task, after
ListFileshas read every footer and the partitioner haspacked every row group into tasks. That re-reads footers of finished files and
leaves a resumed job with one near-empty task per touched file.
This PR gives
ListFilesa single input, the set of finished read unit ids,and drops those units at the earliest point that knows about them. Nothing in
this PR performs checkpointing; it is the hook the checkpoint stack (#65887)
plugs into.
What changes
read_units.py.EXCLUDED_READ_UNIT_IDS_KWARG_NAME, theTaskContext.kwargskey a resumed job sets on theListFilesoperator(
MapOperator.create(map_task_kwargs=...)). Module docstring says how theids flow.
listing/listing_utils.py.list_files_for_each_blockreads the setfrom
ctx.kwargsand passes it toFileIndexer.list_files.listing/file_indexer.py.list_filesand_iter_file_infos_for_listtakeexcluded_read_unit_ids. A file whosepath is in the set is dropped right after path discovery, before any
metadata fetch, so a footer-based indexer never opens it. Ids that name
nothing are ignored.
listing/footer_file_indexer.py. Forwards the set to theFooterReaderactors after the whole-file drop.listing/footer_reader.py._read_and_chunkremoves row groups named<path>#rg<N>before the predicate split and before rows are countedtoward a pushed-down limit, so a resumed job neither re-reads them nor
stops listing early on their account.
chunkers/parquet_file_chunking_utils.py._row_group_unit_id(path, rg)is the one place that spells the row-group id; the chunker and thefooter reader both call it.
tests/unit/datasource_v2/test_read_units.py(new): ids thereader reports round-trip through the footer reader; unknown ids are
ignored and a finished file drops; exclusion happens before predicate and
limit accounting; the plain indexer skips whole files by path; the footer
indexer skips whole files before any footer read and forwards row-group
ids; the listing task forwards the set from
ctx.kwargs; excluding atlisting time packs only the remaining work. One mock in
test_parquet_datasource_v2.pyaccepts the new keyword.Before / after: resuming at 90% done
20 files of 4 row groups each, bins sized to one file. A resume with every row
group finished except the last of the first 8 files (from
test_excluding_units_at_listing_time_packs_only_remaining_work):Behavior
With no excluded ids nothing changes:
excluded_read_unit_idsdefaults toNoneat every layer and the footer reader's row-group range is the samerange(metadata.num_row_groups)as before.Additional information
Not a duplicate: #65887 (checkpoint stack,
[3/4]) drops finished files androw groups with its own per-file compact block threaded through the same
indexer and reader; this PR is the general hook, keyed on
ReadUnit.id, thatwork can call instead. No other open PR touches listing-time exclusion.
Checks run locally from this branch (macOS,
~/ray/.venv):ruff,blackandpydoclintat the pre-commit pins are clean;pyreflyvia
ci/lint/pyrefly-check.shreports 59 errors, identical to the[3/6]head, none new.
Written with Claude Code; I reviewed every changed line and ran the tests above.
🤖 Generated with Claude Code