prefetch: move cache key acquisition to CACHE_LOOKUP_COMPLETE#13238
prefetch: move cache key acquisition to CACHE_LOOKUP_COMPLETE#13238mlibbey wants to merge 1 commit into
Conversation
|
Don't think the autest fail was because of this change -- adding 1 test should not make 114 fail/timeout. [approve ci autest 2of4] |
|
[approve ci autest 2of4] |
There was a problem hiding this comment.
Pull request overview
This PR fixes an ordering bug in the prefetch remap plugin by moving cache key acquisition from POST_REMAP to CACHE_LOOKUP_COMPLETE, where the core guarantees the cache lookup URL has been initialized. It also adds a regression gold test to ensure prefetch.so works correctly without cachekey.so being loaded ahead of it.
Changes:
- Move
TSHttpTxnCacheLookupUrlGet-based cache key acquisition toTS_EVENT_HTTP_CACHE_LOOKUP_COMPLETEand removePOST_REMAPhook usage inprefetchplugin. - Adjust request-MLoc handling logic to match the new hook set (no longer expecting
POST_REMAP). - Add a new gold test (
prefetch_no_cachekey.test.py) covering the standaloneprefetch.soconfiguration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
plugins/prefetch/plugin.cc |
Moves cache key acquisition to CACHE_LOOKUP_COMPLETE and removes POST_REMAP hook registration/handling. |
tests/gold_tests/pluginTest/prefetch/prefetch_no_cachekey.test.py |
Adds regression coverage for running prefetch.so without cachekey.so. |
Comments suppressed due to low confidence (1)
plugins/prefetch/plugin.cc:549
- In the front-end second-pass path, if acquire() succeeds but uniqueAcquire() fails, _fetchable becomes false and TXN_CLOSE will skip releasing the (already-acquired) policy state, causing a leak / incorrect policy accounting. Mirror the schedule() logic: if uniqueAcquire() fails, release() the earlier acquire() before continuing.
/* second-pass */
data->_fetchable = state->acquire(data->_cachekey);
data->_fetchable = data->_fetchable && state->uniqueAcquire(data->_cachekey);
PrefetchDebug("request is %s fetchable", data->_fetchable ? " " : " not ");
| case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE: { | ||
| /* CACHE_LOOKUP_COMPLETE is the earliest hook at which TSHttpTxnCacheLookupUrlGet is | ||
| * guaranteed to return a populated URL: the core does not initialize the cache lookup | ||
| * URL until HttpTransact::HandleRequest runs, which happens after POST_REMAP returns. */ | ||
| if (data->frontend() && data->secondPass()) { |
There was a problem hiding this comment.
I think this is just a matter of adding a
TSHandleMLocRelease(reqBuffer, TS_NULL_MLOC, reqHdrLoc);
when it fails to appendCacheKey().
There was a problem hiding this comment.
indeed -- thanks! Addressed.
|
As commented, this actually fixes an interesting issue (accidentally "prefetching" of likely uncacheable objects). As such, I asked Claude to document this, so here's the suggestion: |
The plugin read TSHttpTxnCacheLookupUrlGet at POST_REMAP, but the core does not initialize the cache lookup URL until HttpTransact::HandleRequest runs after POST_REMAP returns. The call therefore failed unless a plugin like cachekey was called earlier and populated the URL via TSHttpTxnCacheLookupUrlSet, making prefetch silently dependent on cachekey's presence and remap ordering. Acquire the cache key at CACHE_LOOKUP_COMPLETE instead, which is the first hook where the lookup URL is guaranteed to be set. On transactions where ATS skips cache lookup (non-cacheable methods, internal redirects, cache disabled), the front-end first-pass admission acquire no longer fires. TXN_CLOSE release is gated on _fetchable, so acquire/release symmetry is preserved. Also fix a missing release in the second-pass acquire/uniqueAcquire sequence: if uniqueAcquire fails after acquire succeeds, release the acquired cache key to avoid orphaning it in the policy LRU. The four existing prefetch autests all pair cachekey.so ahead of prefetch.so and would have passed with or without this fix. Adds prefetch_no_cachekey.test.py to regression-cover the standalone case.
59ba52e to
2dc2c08
Compare
Thanks! Added a similar section in now. |
The prefetch plugin read TSHttpTxnCacheLookupUrlGet at POST_REMAP, but the core does not initialize the cache lookup URL until HttpTransact::HandleRequest runs after POST_REMAP returns. The call therefore failed unless a plugin like cachekey was called earlier and populated the URL via TSHttpTxnCacheLookupUrlSet, making prefetch silently dependent on cachekey's presence and remap ordering. Acquire the cache key at CACHE_LOOKUP_COMPLETE instead, which is the first hook where the lookup URL is guaranteed to be set.
On transactions where ATS skips cache lookup (non-cacheable methods, internal redirects, cache disabled), the front-end first-pass admission acquire no longer fires. TXN_CLOSE release is gated on _fetchable, so acquire/release symmetry is preserved.
The four existing prefetch autests all pair cachekey.so ahead of prefetch.so and would have passed with or without this fix. Adds prefetch_no_cachekey.test.py to regression-cover the standalone case.