Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request enhances the MCAP datasource by opening files for random access to leverage the MCAP chunk index, introducing a log_time_order option to control message sorting, and streaming files in blocks based on target_max_block_size. Feedback on these changes highlights a potential performance bottleneck from calling get_estimated_memory_usage() on every row, suggesting it be checked periodically instead. Additionally, a correctness concern was raised regarding potential schema inconsistencies across blocks when a multi-topic file is split into multiple blocks.
marwan116
force-pushed
the
marwan/mcap-seekable-read
branch
from
October 2, 2026 04:04
64b8dca to
7532acf
Compare
This was referenced Oct 2, 2026
…e_order `MCAPDatasource` read every file through a sequential stream, so the mcap library always took its non-seeking path: - The summary at the file's tail (per-chunk time bounds and byte offsets, per-channel message counts) was unreachable. `topics` and `time_range` were applied per record over a full scan rather than used to skip the chunks that cannot match, despite the class docstring advertising predicate pushdown. - `log_time_order=True` was hard-coded. On the non-seeking reader that loads and sorts the entire file before the first message is returned, which its own docstring warns about. - A file was one block, however large it was. Open the file for random access (`open_input_file`), the hook `FileBasedDatasource` documents for implementations that need it. `make_reader` then returns a `SeekingReader`, which prunes chunks by topic and time from the index and merges chunks by log time as it goes instead of sorting the file in memory. Files written without a summary still read: the seeking reader falls back to a linear scan when there is no chunk index. Cut blocks by estimated size: yield a block as soon as the builder reaches the context's `target_max_block_size`. Memory per read task is bounded by the target instead of by the file, and the first block of a large file arrives before the file has been read to the end. `target_max_block_size = None` keeps one block per file. Expose `log_time_order` on `read_mcap`. The default, True, keeps today's output. False streams a file in the order it was written and skips the merge, which is the right choice when order does not matter or when the file's chunks do not overlap in time. Rewinding between retry attempts is no longer this class's concern: `FileBasedDatasource.read_files` reopens the file for every attempt (#66011). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Marwan Sarieddine <[email protected]>
marwan116
force-pushed
the
marwan/mcap-seekable-read
branch
from
October 5, 2026 18:31
7532acf to
2c5ec5d
Compare
Contributor
Author
richardliaw
pushed a commit
that referenced
this pull request
Nov 6, 2026
…, row_id (#66654) ## Description Part 1 of 3 of the `read_mcap` move to Datasource V2, based on master. #67166 is stacked on it, and #67167 on #67166. The rest of the `read_mcap` stack (#67189 onward) sits on top. **Problem.** One task reads one whole file: - Parallelism is capped by the file count: ten 30 GB recordings are ten tasks. - Every file is opened, even when its index shows it holds nothing selected. - Rows have no stable id, so a checkpointed pipeline cannot resume. **Change.** `read_mcap` moves to Datasource V2, on by default as for `read_parquet` (`DataContext.use_datasource_v2`). The legacy datasource stays as the fallback. ``` files │ listing: read each file's index (a few ranged reads) │ one row per chunk, weighted by the memory reading it takes │ drop chunks that cannot match topics / time_range ▼ chunk rows │ packing: about 128 MiB per read task │ one big file ──► many tasks; small files ──► one task │ with preserve_order: one task per file, in listing order ▼ read tasks: seek to their chunks, merge them by log time ``` - New code lives in `datasource_v2/formats/mcap/`. The V2 interfaces do not change. - Columns and types match the legacy path, with two changes. `schema_data` is dictionary-encoded. A new `channel_metadata` column holds each channel's metadata map as JSON text, dictionary-encoded, so a block stores it once per channel. - `data` holds decoded JSON only when every selected channel is JSON. Otherwise it holds bytes. Planning types it from the selected messages of the first chunk that holds one, as a read task types the messages it holds. - `row_id` is `<path>#c=<chunk offset>:<index>`, stable however the read is split. It is on with `include_row_id=True`, or automatically under `CheckpointConfig(id_column="row_id")`. - New `log_time_order` argument, default `True`. Each task returns each of its files in `log_time` order. With `preserve_order`, each file is read by one task, so it comes out in order from start to end, and files come out in the order they were listed. #67166 splits a large file there too, only where its order holds. - A file whose summary cannot be read gets a read task of its own, so `max_errored_blocks` can skip it alone. - The task size is `RAY_DATA_MCAP_BIN_PACKING_BYTES` (128 MiB). **Changed after the first review round.** Each is its own commit: - Summaries and chunks are read in a few ranged requests, not a few bytes per GET. - An unreadable file gets a read task of its own. - Tables are built column by column, cut counting every column, and chunks are weighted by the memory reading them takes. - The read stops at the row limit. - A file without a chunk index is sorted by log time. - `channel_metadata` is JSON text, stored once per block. - With `preserve_order`, each file is kept in one read task, and files keep their listing order. - Planning skips a chunk it cannot decode, and types `data` from the first chunk's messages. **Measured** on an 845 MB recording with 1,052 chunks: reading its 125 KB summary took about 20,000 GETs and now takes 3. **Decisions to confirm:** - Splitting is on by default. Block boundaries change; rows do not. - With `preserve_order`, this PR reads each file in one task, as the legacy reader does. #67166 lets it split a large file where its log-time order holds. - `ds.schema()` comes from the first chunk that holds a selected message. A field that first appears later is missing from it; the docstring says so. ## Related issues - Related to #65640 and #65641. - No open PR moves MCAP to Datasource V2. #66524 (ORC) and #66182 (Iceberg) are other formats moving to V2. - The generated-ID stack (#65886 to #65888) is orthogonal. - `log_time_order` comes from my #66653, now closed. My legacy-path PRs #65912, #65913 and #65916 are closed in favour of this one. ## Additional information ``` PYTHONPATH=python/ray/data/tests pytest python/ray/data/tests/datasource/test_mcap.py \ python/ray/data/tests/unit/datasource_v2/test_mcap_*.py \ python/ray/data/tests/unit/datasource_v2/test_online_bin_packer.py ``` 178 passed, 3 skipped. pre-commit and pyrefly clean. AI assistance (Claude Code) was used to draft this change; I reviewed every line and ran the tests above locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Marwan Sarieddine <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Part 1 of 6 of the
read_mcapredesign. The other five PRs are stacked on this branch.Problem.
MCAPDatasourceopens each file as a one-way stream, so the mcap library uses its non-seeking reader:topicsandtime_rangefilter only after a full scan.log_time_order=Trueloads and sorts the whole file before returning anything.Change. Three small edits to the existing datasource:
DataContext.target_max_block_size.log_time_orderonread_mcap. The default staysTrue.Files without an index still read, by linear scan.
Measured on a 230 MB recording on local disk:
time_rangeover the last 10%Related issues
batch_sizeparameter. This PR cuts blocks by bytes instead, and also fixes how files are opened. I explained this on [Data] Add batch_size to MCAPDatasource for streaming reads #66190.Additional information
22 passed (18 on master). pre-commit clean.
AI assistance (Claude Code) was used to draft this change; I reviewed every line and ran the tests above locally.
🤖 Generated with Claude Code