Xuanwo opened a new pull request, #8972: URL: https://github.com/apache/opendal/pull/8972
# Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> None. # Rationale for this change `opendal-layer-foyer` had five correctness and safety gaps across cache-miss error propagation, delete/append invalidation, stat fallback, and size-limit enforcement: 1. `FetchError::Source` and `extract_err` stripped `ErrorStatus` (`Temporary` / `Persistent`) and original source/context from backend errors on cache misses, preventing an outer `RetryLayer` from retrying transient failures. 2. `Deleter::delete` deferred all cache invalidation until `close()`, leaving deleted objects permanently cached when `OneShotDeleter` committed immediately or a `BatchDeleter` partially flushed before returning an error in `delete_iter` (which does not call `close()`). 3. `FullReader::read_full_object` unconditionally called `stat` (failing with `Unsupported` on services without `stat` or `stat_with_version`), cast `content_length()` with `as usize` (truncating `>= 4 GiB` sizes on 32-bit targets), skipped `metadata.is_file()` checks, and did not bound or re-check `size_limit` against the actual bytes read when an object changed between `stat` and `read`. 4. `FoyerLayer::with_size_limit` computed `*v + 1` on `Bound::Included(usize::MAX)` and `Bound::Excluded(usize::MAX)`, panicking in debug builds and wrapping to an inverted/empty range in release builds. 5. `Writer` deferred append invalidation until a successful `close()`, leaving stale cached data behind when an append writer persisted bytes during `write()` and was subsequently aborted, dropped, or failed on `close()`. # What changes are included in this PR? - Preserve `ErrorStatus` (`Temporary` / `Persistent` / `Permanent`) and original error source in `FetchError::Source(Arc<Error>)` and `extract_err` (`core/layers/foyer/src/error.rs`, `core/layers/foyer/src/full.rs`). - Invalidate exact keys (and clear cache for recursive deletes) during `Deleter::delete` on success and on mid-batch/recursive failure while keeping `close()`'s `DeleteGuard` for buffered deleters; standalone failed non-recursive deletes continue to leave cached entries untouched (`core/layers/foyer/src/deleter.rs`). - Fall back to direct uncached reads in `FullReader::read_full_object` when `size_limit` is empty, `stat`/`stat_with_version` is unsupported, metadata is not a regular file, or `usize::try_from(metadata.content_length())` overflows; bound stream reads by `size_limit.end` and return shrunk out-of-range objects uncached via `FetchError::Uncached` (`core/layers/foyer/src/full.rs`). - Use `v.saturating_add(1)` in `FoyerLayer::with_size_limit` and `saturating_add` in `Writer::write` size accumulation (`core/layers/foyer/src/lib.rs`, `core/layers/foyer/src/writer.rs`). - Evict the unversioned cache entry on `Writer::write` and `Writer::close` (on both `Ok` and `Err`) for append writes while preserving non-append abort behavior (`core/layers/foyer/src/writer.rs`). - Update layer operation documentation and add unit and integration tests covering all five fixes (`core/layers/foyer/src/lib.rs`, `core/layers/foyer/tests/cache_invalidation.rs`, `core/layers/foyer/Cargo.toml`). # Are there any user-facing changes? - Cache-miss temporary backend errors now retain `is_temporary()` so outer `RetryLayer` stacks retry them as expected. - Services without `stat` or `stat_with_version` now fall back to direct reads instead of failing with `Unsupported`. - Deleted and partially appended objects are invalidated promptly rather than serving stale cached entries. - `FoyerLayer::with_size_limit` safely accepts `usize::MAX` bounds without panicking or wrapping. # Breaking changes # AI Usage Statement - Harness: pi - Model: Gemini 4 Neon - Effort: high - Role: Verified all five findings against `main`, implemented the fixes and deterministic unit/integration tests in `opendal-layer-foyer`, and ran local formatting, clippy, rustdoc, typo, and test checks. -- 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]
