pdad opened a new pull request, #24420:
URL: https://github.com/apache/kafka/pull/24420

   `NamedCache#flush` marked every dirty entry clean before the flush listener 
wrote the entries to the underlying store. If the stream thread read the same 
caching store while the listener was running (e.g. a downstream KTable join 
reading through value getters while the flushed records are forwarded), a cache 
miss in `CachingKeyValueStore#getInternal` put a clean entry into the cache, 
and the resulting eviction silently dropped entries that were marked clean but 
not written yet. A later read of such a key loaded the old value from the 
underlying store and cached it as clean; the flush then wrote the new value, 
but the cache kept serving the old one, so the next read-modify-write (e.g. a 
KTable aggregation) lost an update. The changelog briefly contains the correct 
value, followed by a value derived from the older one.
   
   Entries now stay dirty until the listener has written them (they are marked 
clean after the listener returns, also if it throws). An entry that is evicted 
while its flush is in progress is no longer dropped: `NamedCache` keeps serving 
it until that flush completes. The listener still receives the whole batch, 
because `TimeOrderedCachingWindowStore` de-duplicates base and index keys 
across it.
   
   Testing:
   - 
`CachingInMemoryKeyValueStoreTest#shouldNotCacheStaleValueWhenReadDuringItsOwnFlush`
 reproduces the issue at store level (fails on trunk: the cache serves the old 
value).
   - `NamedCacheTest`: an entry evicted during its flush is served during the 
flush, not afterwards, not flushed twice, not served after a delete, and 
entries are marked clean when the listener throws.
   - The `TopologyTestDriver` reproducer attached to KAFKA-21673 passes with 
this change (0 of 100 updates lost; 1 of 100 on 4.2.2 and 4.4.0).
   
   Co-Authored-By: Claude Opus 5.5 <[email protected]>
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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