chitralverma opened a new pull request, #9382:
URL: https://github.com/apache/opendal/pull/9382

   # Which issue does this PR close?
   
   Part of #9324 (tracker #9320).
   
   # Rationale for this change
   
   #9331, #9361, #9366, and #9378 generate the C++ `ListOptions`, 
`StatOptions`, `DeleteOptions`, and `ReadOptions` from 
`core/core/src/types/options.rs`. This PR generates the existing 
`ReaderOptions` the same way, reusing their table, templates, and tests. It 
exposes no new option.
   
   # What changes are included in this PR?
   
   - `dev/src/generate/cpp.rs`: `OPTIONS` lists the 10 `ReaderOptions` members 
with their core kinds, in their released order. Every kind already crosses the 
bridge; `prefetch` (`Usize`) is `std::size_t prefetch{0}`, as `concurrent` is. 
Core's `if_version_match`, `if_version_not_match`, and `checksum` stay 
unexposed and keep their core defaults, as `main`'s `..Default::default()` did; 
the generated conversion lists them under `// Not exposed in C++ yet:`. 
Timestamps can fail to convert, so the conversion is a `TryFrom`.
   - `data_structure.hpp`, `src/lib.rs`, and `src/operator.cpp` drop the 
hand-written `ReaderOptions`, `FfiReaderOptions`, `reader_options` conversion, 
and `ToFfiOptions(const ReaderOptions &)`. Only `ReaderOptions` used `lib.rs`'s 
`OptionalTimestamp` bridge struct, `optional_timestamp`, and `operator.cpp`'s 
`ToFfiOptionalTimestamp`, so they go too. `Operator::GetReader(path, options)` 
and the `reader_options` bridge function keep their signatures. 
`Operator::reader_options` in `lib.rs` still converts the options, then stats 
the file with `version` and the five conditions unless `content_length_hint` is 
set, then creates the reader, as on `main`.
   - Docs: core's `ReaderOptions` docs as of #9381, rendered by the rules of 
#9361 and #9378. Where core describes what C++ `GetReader` and `Reader` do 
differently, the docs use C++ forms:
     - Struct doc: "Creating the reader checks the options and capabilities 
without accessing storage, so a missing file or a failed condition surfaces 
when reading from it." reads "Unless `content_length_hint` is set, 
`opendal::Operator::GetReader` first stats the file to learn its length. That 
stat carries `version` and the conditions, so a missing file or a failed 
condition fails `GetReader`, and each of them also needs its stat capability, 
such as `opendal::Capability::stat_with_if_modified_since` for 
`if_modified_since`; otherwise `GetReader` fails with `Unsupported`. With 
`content_length_hint` set, `GetReader` checks the options and capabilities 
without accessing storage, so a missing file or a failed condition surfaces 
when reading from the reader."
     - `content_length_hint` adds: "When it is set, 
`opendal::Operator::GetReader` does not stat the file, and the reader takes 
this value as the file length: `opendal::Reader::Read` stops there, and seeking 
relative to the end starts there. With a value larger than the file, a `Read` 
that reaches past the end of the file fails."
     - `concurrent`: "Without `chunk`, only `Reader::fetch` reads concurrently, 
with one request per merged range." reads "Without `chunk`, OpenDAL does not 
read concurrently." C++ has no `fetch`.
     - `chunk`: core's paragraph on when a chunked read with an open-ended or 
suffix range stats the file reads "`opendal::Reader::Read` and 
`opendal::Reader::ReadAt` read a range with an end, so a positive `chunk` does 
not make them stat the file."
     - `gap` reads "Each call to `opendal::Reader::Read` or 
`opendal::Reader::ReadAt` reads a single byte range, so `gap` has no effect." 
Core documents how `Reader::fetch` merges ranges.
     - Every other member doc is core's full text with C++ names. Generation 
fails when a rewrite matches nothing, so a reworded core sentence gets reviewed 
again.
   - Tests:
     - `dev`: the `ReaderOptions` text copied from `main`'s 
`data_structure.hpp` must appear in the generated header once comments are 
removed, which now declares six structs. The doc test compares each 
`ReaderOptions` member doc and the struct doc with core's full doc, paragraph 
by paragraph, after applying the C++ member doc and rewrites, which the test 
holds as literals. It also checks that the `ReaderOptions` docs never mention 
`::fetch`, that `opendal.hpp` declares `GetReader(std::string_view path, const 
ReaderOptions &options)`, and that each `opendal::Operator::` and 
`opendal::Reader::` method the header docs name is declared in that class. 
Generation fails when core changes the kind of `content_length_hint`, 
`concurrent`, `gap`, or `prefetch`, drops `prefetch`, or rewords the text of 
any of the four rewrites.
     - `src/options_test.rs`: every bridge field reaches core, explicit zeros 
stay `Some(0)`, absent values stay absent, and out-of-range timestamps fail.
     - `tests/options_test.cpp`:
       - A positional initializer in `main`'s member order reaches the bridge. 
Structured bindings bind the 10 members in order. A default `const 
ReaderOptions` reaches the bridge absent.
       - On `memory`, each member returns the whole file. `chunk` reaches core: 
with a hint two bytes past the end of the file, reading fails with `Unexpected` 
without `chunk` or with `chunk = 0`, and with `RangeNotSatisfied` with `chunk = 
2`.
       - On `memory`, the reader takes `content_length_hint` as the file 
length: `Read` stops at a smaller hint, seeking from the end starts at the 
hint, and a larger hint fails the `Read` that reaches past the end of the file. 
Without the hint, seeking from the end starts at the stat's length.
       - On `memory`, without the hint, `GetReader` of a missing file fails 
with `NotFound` at `stat`; with the hint, the first `Read` does. Each of the 
five conditions fails `GetReader` with `Unsupported`, naming the `stat` 
operation without the hint and `read` with it, for an existing and a missing 
file.
       - On `fs`, which has `read_with_if_modified_since` but not 
`stat_with_if_modified_since`, `if_modified_since` fails `GetReader` with 
`Unsupported` at `stat` for an existing and a missing file. With the hint, the 
file reads, a missing file fails `Read` with `NotFound`, and a future time 
fails it with `ConditionNotMatch`.
   
     Scratch mutations confirmed that each new test can fail:
     - Generator: dropping the `gap` doc or any of the four rewrites, changing 
the `content_length_hint` wording, swapping `if_match` and `if_none_match`, 
exposing `checksum`, moving `prefetch` before `gap`, or dropping the `{0}` 
initializer of `Usize` members fails a doc or declaration test. Skipping the 
kind check or the stale rewrite check fails a spec test. Naming a method 
`opendal::Operator` does not declare fails the doc test.
     - Core: changing `prefetch` or `concurrent` to `Option<usize>`, removing 
`prefetch`, or rewording the text of any of the four rewrites makes `generate 
-l cpp` exit with an error. Adding a field to core `ReaderOptions` only adds it 
to the `// Not exposed in C++ yet:` list.
     - Binding: in the generated Rust conversion, dropping `prefetch` or 
`chunk` fails a Rust test, and dropping `chunk` or `version` fails a C++ test. 
In the generated C++ converter, sending `prefetch` as 0, `content_length_hint` 
as absent, or `if_match` and `if_none_match` swapped fails a C++ test. In 
`lib.rs`, statting without the conditions or ignoring `content_length_hint` 
fails a C++ test.
   
   Verification of the generated doc claims, through this binding on `memory`, 
`fs`, and versioned Silo S3 (the CI fixture image), with Silo's request trace 
(`mc admin trace`) for what the reads send:
   
   - Without `content_length_hint`, `GetReader` sends one `HeadObject`. With 
it, `GetReader` sends nothing. Each `Read` or `ReadAt` call then sends one 
ranged `GetObject`, with `gap = 0`, with `concurrent = 4` alone, and with the 
default options. With `chunk = 3` and `concurrent = 4`, a 10-byte `Read` sends 
four ranged `GetObject`s, out of order. With `chunk = 4`, `Read`, `ReadAt`, and 
`Seek` followed by `Read` send no further `HeadObject`.
   - On Silo, without the hint, a missing file fails `GetReader` with 
`NotFound` at `stat`. An unknown `version` does too. A failing `if_match`, 
`if_none_match`, `if_modified_since`, or `if_unmodified_since` fails it with 
`ConditionNotMatch` at `stat`. With the hint, `GetReader` succeeds and the 
first `Read` fails with the same kind at `read`. Matching conditions and the 
current `version` read the file either way.
   - On `memory`, each of the five conditions fails `GetReader` with 
`Unsupported` at `stat` without the hint and at `read` with it, for an existing 
and a missing file. On `fs`, `version`, `if_match`, and `if_none_match` do the 
same. `if_modified_since` and `if_unmodified_since` fail with `Unsupported` at 
`stat` without the hint. With the hint, they read the file or fail `Read` with 
`ConditionNotMatch`, and a past `if_modified_since` with `chunk = 2` also reads 
the file.
   - On all three, a hint of 0, 4, or 10 makes `Read` return that many bytes, 
and seeking from the end starts at the hint. A hint of 12 or 100 for a 10-byte 
file fails the `Read` that reaches past the end.
   
   # Are there any user-facing changes?
   
   None in the API. `ReaderOptions` moves from `data_structure.hpp` to 
`options.hpp`, which `data_structure.hpp` includes, so code that includes 
either header sees the same declarations. With comments removed, the headers in 
`include/` have the same lines as on `main`, and all 28 struct, class, and enum 
class definitions match; `ReaderOptions` is the only one that moved. 
`ReaderOptions` gains doc comments; on `main` it had only its `@brief`.
   
   A probe compiled against `main`'s and this PR's headers printed identical 
output: `sizeof`, `alignof`, aggregate and standard-layout status of all eight 
options structs and `ReadRange`, the offset, type, and default of every 
`ReaderOptions` member, and the values from full and partial positional 
initialization, value initialization, C++20 designated initialization, and 
structured bindings. Compiler warnings were identical too. This held on Linux 
x86-64 with GCC 13.3 and clang 18.1.3, in C++17 and C++20. `ReaderOptions` 
stays 216 bytes with 8-byte alignment.
   
   # Breaking changes
   
   None
   
   # AI Usage Statement
   
   - Harness: Claude Code via T3 Code. Model: Claude Opus 5.5 
(`claude-opus-5-5`). Effort: xhigh. Role: implemented the generator table 
entry, the C++ doc forms, the binding wiring, and the tests. Ran the doc-claim 
checks on `memory`, `fs`, and Silo S3, plus the mutation, layout, and Linux 
container checks. Drafted this description. The author reviews every change and 
claim.
   - Decisions for review:
     - The four rewrites and the `gap` doc describe `Operator::reader_options` 
in `lib.rs`, which this PR does not change. It stats the file before it creates 
the reader unless `content_length_hint` is set, and its `Reader` reads bounded 
ranges. Everything else is core's text.
     - The `content_length_hint` doc now states that the C++ reader takes the 
hint as the file length, as `lib.rs` has always done. The C++ tests on `memory` 
pin that behavior.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to