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

   # Which issue does this PR close?
   
   None. The report is below.
   
   # Rationale for this change
   
   The Foyer service documents `memory` in bytes. When OpenDAL built the cache, 
it used Foyer's default weight of one per entry, so a small byte budget could 
retain many more bytes than requested.
   
   To reproduce on `7d82742467f7` with Foyer 0.22.6, construct 
`Operator::new(Foyer::new().root("cache").memory(24).shards(1))` with the 
`services-foyer` feature. Leave `disk_path` unset. Write `"abc"` to `"é"`, read 
it back, then write `"1234567"` to `"b"` and read both keys. The first entry 
weighs 11 bytes (`cache/é` is 8 UTF-8 bytes plus 3 value bytes). The second 
weighs 14 bytes (`cache/b` is 7 bytes plus 7 value bytes). Each fits on its 
own, but together they exceed the 24-byte budget. On the base, both reads 
succeed. With this fix, `read("é")` returns `NotFound` as expected and 
`read("b")` returns `"1234567"` intact.
   
   The mismatch also reproduces on v0.59.5. With one shard and `memory(64)`, 
four distinct keys holding 8, 16, 24 and 32 bytes all remained readable, 
totaling 80 bytes of values alone.
   
   # What changes are included in this PR?
   
   The service sets an explicit weight when it builds a cache. Each entry 
counts the byte length of its stored path plus the logical length of its value, 
with a minimum charge of one byte. The stored path includes the normalized 
operator root and omits the leading slash.
   
   A regression test covers the two-key case above. The disk-backed test 
fixture now uses a byte budget that still forces the target onto disk. The 
service guide, Java and Python configuration docs, and website catalog describe 
the byte budget. The service and layer examples show the unit used by Foyer's 
default weighter for caller-built caches.
   
   # Are there any user-facing changes?
   
   Yes. `FoyerBuilder::memory` and the serialized `memory` option now apply the 
documented byte budget (default 1 GiB) to eviction in automatically built 
caches. Foyer evicts within each shard and can still admit an entry larger than 
that shard's budget after evicting its other entries. Process RSS also includes 
allocations such as cache bookkeeping. A `HybridCache` supplied through 
`FoyerBuilder::cache` or `FoyerLayer` uses the caller's capacity and weighting 
policy.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Pi, `magpie/codex/gpt-6.2-astra`, `xhigh` effort coordinated the 
investigation and fix.
   - Pi, `magpie/codex/gpt-6.2-sol`, `max` effort reproduced the behavior, 
implemented the fix and tested it.
   - Pi, `magpie/codex/gpt-6.2-astra`, `high` effort analyzed the eviction 
behavior and drafted the PR description.
   - Pi, `magpie/devin/swe-2-1`, default effort independently reviewed the 
patch and reran the two-key regression on the base and candidate.
   


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