Repository navigation
Remote cache: fix write-back during hedged reads and a getParams edge case (#2251) - #2251
GijsWeterings wants to merge 1 commit into
Conversation
|
@GijsWeterings has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133210770. |
… case (#2251) Summary: Follow-ups from the react/metro review of the two remote cache changes (#2249, #2246). **A hedged local transform no longer writes to a remote store that is about to hit.** `Cache.set` skips the store that served a hit and the stores after it, using `Cache.#hits`, which is only filled once a `get` returns. With `unstable_hedgeCacheReadsAfterMs`, the local transform can win while the remote read is still pending, so `set` wrote to every store: with a read-write remote (`HttpStore`), one redundant upload per file that already exists remotely, on the congested link the option is for. `HttpGetStore` does not write, so the setup this was built for was not affected. `Cache` now tracks the store each pending `get` is reading. A `set` during that read writes the stores the read has already missed at once, and the rest when the read settles, stopping at the store that hit: the same stores a `set` after the read would write. On a miss everything is still written; nothing changes when no read is pending. The bookkeeping is one small object per `get`, and a promise only when a `set` overlaps it. **`getParams` resolving to a plain object or nothing is a cache miss, not a build failure.** The parameters are now built with `new URLSearchParams(extra ?? undefined)` inside the guarded part, so a plain object such as `{token: 'abc'}` is used as parameters and `undefined`/`null` adds none, and anything else that fails becomes a `NetworkError`. Errors from the request itself are still not wrapped. **Docs:** `Configuration.md` said racing transforms run at most `maxWorkers` at a time; they share `2 * maxWorkers` slots with cache-miss transforms. `Caching.md` describes the write order when a write overlaps a read. Changelog: [Fix] metro-cache: a result written while a read of the same key is still under way no longer writes to the store that read then hits, and an `HttpStore` `getParams` that resolves to a plain object or nothing no longer fails the build Differential Revision: D133210770
a0c6a6f to
6366581
Compare
Metro review: Looks goodRisk: low · Commit: The PR records which store each pending No findings. Verified
Benchmarks (base vs this PR)
Method
Not run: Windows was not run because no Windows machine was available for this review, and the change uses no paths or other platform-specific behavior. I didn't run an end-to-end build against a real HttpStore remote. The overlap behavior is covered by the unit tests in Cache-test.js and Transformer-test.js. Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
robhogan
left a comment
There was a problem hiding this comment.
Thanks for following up!
Summary:
Follow-ups from the react/metro review of the two remote cache changes (#2249, #2246).
A hedged local transform no longer writes to a remote store that is about to hit.
Cache.setskips the store that served a hit and the stores after it, usingCache.#hits, which is only filled once agetreturns. Withunstable_hedgeCacheReadsAfterMs, the local transform can win while the remote read is still pending, sosetwrote to every store: with a read-write remote (HttpStore), one redundant upload per file that already exists remotely, on the congested link the option is for.HttpGetStoredoes not write, so the setup this was built for was not affected.Cachenow tracks the store each pendinggetis reading. Asetduring that read writes the stores the read has already missed at once, and the rest when the read settles, stopping at the store that hit: the same stores asetafter the read would write. On a miss everything is still written; nothing changes when no read is pending. The bookkeeping is one small object perget, and a promise only when asetoverlaps it.getParamsresolving to a plain object or nothing is a cache miss, not a build failure. The parameters are now built withnew URLSearchParams(extra ?? undefined)inside the guarded part, so a plain object such as{token: 'abc'}is used as parameters andundefined/nulladds none, and anything else that fails becomes aNetworkError. Errors from the request itself are still not wrapped.Docs:
Configuration.mdsaid racing transforms run at mostmaxWorkersat a time; they share2 * maxWorkersslots with cache-miss transforms.Caching.mddescribes the write order when a write overlaps a read.Changelog: [Fix] metro-cache: a result written while a read of the same key is still under way no longer writes to the store that read then hits, and an
HttpStoregetParamsthat resolves to a plain object or nothing no longer fails the buildDifferential Revision: D133210770