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

   # Which issue does this PR close?
   
   Part of #7107 (RFC-8569 `CacheLayer` conformance and edge-case fixes).
   
   # Rationale for this change
   
   An RFC-8569 audit of `core/layers/cache` identified five read-path and 
singleflight defects:
   
   1. **Tier 4 (`Nonce`) thrashing and large-read misses:** Reads larger than 
one fill unit (`FILL_BYTES` / `FILL_CHUNKS`) on validator-free backends 
(`Memory`) discarded the discovery unit, fell back to origin, and then deleted 
the fresh pointer on every subsequent read. Partial-range misses on a fresh 
Tier 4 pointer also deleted the pointer and orphaned already-cached chunks.
   2. **Short `Suffix` bypass in `CachedReader::read`:** Comparing `data.len()` 
against the raw `Suffix(n)` size caused valid short suffix reads (where 
`object_len < n`) to discard cached bytes and fall back to origin on every call.
   3. **Cold `Suffix` and `Fs`/`PositionReader` amplification:** Cold `Suffix` 
reads opened a source stream and discarded its body before issuing another 
aligned open (2 GETs on object stores). On services returning empty `RpRead` 
(such as `Fs`), `fetch_unit` opened the source, discarded it after 
`verify_stat`, and opened a second time even though `pointer` was already 
observed before the fresh handle was created.
   4. **`discover()` error handling:** `read_unit()` errors bypassed 
`fill_open_error`, skipping the RFC-mandated pre-first-byte retry on 
`ConditionNotMatch` (e.g. from an inner `RetryLayer`). `stat()` errors other 
than `Unsupported` were swallowed when `RpRead` lacked a validator, allowing 
stale Tier 4 pointers to be published after `NotFound` or auth failures.
   5. **Singleflight executor integration:** `Flights::run` only checked 
`tokio::runtime::Handle::try_current()`, bypassing 
`OperationContext::executor()` on non-Tokio executors.
   
   # What changes are included in this PR?
   
   - Add single-open `NonceFillStream` for large Tier 4 reads, stream large 
cached Tier 4 ranges lazily after boundary chunk checks without reopening 
origin on mid-stream eviction, and keep fresh Tier 4 pointers intact on partial 
misses instead of discarding them.
   - Compare `CachedReader::read` suffix responses against 
`expected.min(content_length)` so valid short suffix reads are served from 
cache.
   - Resolve cold `Suffix` reads via `stat` when supported (publishing 
verifiable pointers directly before fetching aligned chunks), and remove the 
redundant pre-stat drop-and-reopen in `fetch_unit`.
   - Map `discover()` stream errors through `fill_open_error` and propagate 
`NotFound`/non-`Unsupported` `stat` failures without caching unverified 
pointers.
   - Submit detached singleflight tasks through `OperationContext::executor()` 
first, falling back to Tokio / inline execution only when no executor accepts 
submission.
   - Add regression tests in `core/layers/cache/tests/read_through.rs` covering 
all five fixes plus RFC-8569 mutation invalidation coverage for 
`Writer::copy_from`, `compose`, `restore`, and versioned `delete`.
   
   # Are there any user-facing changes?
   
   - Large reads and partial-range reads on Tier 4 backends (`Memory`) now 
cache and hit without pointer thrashing.
   - Short suffix reads via `oio::Read::read` now hit cache, and cold suffix / 
`Fs` chunk-miss reads issue fewer redundant source operations.
   - Singleflight background fills now honor custom executors configured on 
`OperationContext`.
   - No public API changes.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: Pi (T3 Code)
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Audited `core/layers/cache` against RFC-8569, implemented the five 
fixes and regression/validation tests, and verified formatting, clippy, 
rustdoc, `wasm32-unknown-unknown` compilation, and `opendal-layer-cache` 
unit/doc tests. Tests use in-process `Memory` and `Fs` backends; no live remote 
service requests were made.
   


-- 
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