Honor the RamCache copy flag in LRU and S3-FIFO#13380
Draft
phongn wants to merge 1 commit into
Draft
Conversation
CacheVC requests copy semantics (put copy=true) whenever RAM cache compression is configured, because it unmarshals HTTP headers in place in its own buffer after the put and again on every RAM hit. LRU and S3-FIFO ignored the flag and shared buffers with the caller in both directions, so with proxy.config.cache.ram_cache.compress enabled and algorithm=1 (the default) or 2, the cached bytes were mutated after insertion and every subsequent HTTP RAM hit re-unmarshalled an already-unmarshalled header (assert in debug builds, header unmarshal failure in release). Copy entries now copy on put, copy on get, and a copy=true put refreshes a resident entry that may still be sharing a caller's buffer, matching CLFUS. This is a backport candidate for all release branches. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
514d888 to
1b53b1e
Compare
Collaborator
Author
|
Tracking issue: #13381 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
put(..., copy = true)is the caller's contract that buffers may not be shared between the cache and the caller in either direction.CacheVCrequests it whenever RAM cache compression is configured (http_copy_hdr,CacheVC.cc), because it unmarshals HTTP headers in place in its own buffer after the put, and again on every RAM-cache hit.The LRU and S3-FIFO RAM caches ignored the flag and shared buffers both ways. With
proxy.config.cache.ram_cache.compressset andalgorithm = 1(the default) or2:HTTPInfo::unmarshalfails on the already-unmarshalled header (ink_assertin debug builds; broken HTTP RAM hits in release).The
http_copy_hdrgate keys off the compress config only, never the algorithm, so this is reachable purely by configuration today. This correctness fix stands alone (compression support for LRU is proposed separately) and is a backport candidate.Changes
RamCache::copy_data_in()/RamCache::copy_data_out()on the base class; CLFUS's three pre-existing open-coded copies of the same logic are replaced with calls to them (no behavior change).RamCacheLRUandRamCacheS3FIFOnow honorcopythe way CLFUS always has: copy on put, copy on get, and acopy = trueput refreshes a resident entry that may still be sharing a caller's buffer from before a configuration change.copy = falsebehavior is unchanged: zero-copy sharing, pinned by a test.test_RamCacheCopy) pins the contract for all three policies: caller mutation after put, caller mutation of the returned buffer, the resident-refresh transition, and copy=false sharing. Before the fix, the three copy cases fail for LRU and S3-FIFO; CLFUS passes.Notes for reviewers
block_size()recovers the data length and neither entry struct needs a new length field.