amaliujia opened a new pull request, #1595:
URL: https://github.com/apache/ratis/pull/1595

   ## What changes were proposed in this pull request?
   
   Fixes incorrect totalCacheSize accounting in LogSegment.putEntryCache() when 
a cache entry is overwritten under the same key.
   
   When duplicate inserts occur (e.g. concurrent segment loads), the method was 
computing the size of the replaced entry from the new value instead of the 
previous one. That made the delta zero on overwrite, so totalCacheSize could 
drift when the new entry had a different size than the old one. This in turn 
fed wrong memory accounting into SegmentedRaftLogCache.
   
   The fix is a one-line change: use getEntrySize(previous, Op.REMOVE_CACHE) 
instead of getEntrySize(value, Op.REMOVE_CACHE).
   
   Added testPutEntryCacheDuplicateKeyUpdatesTotalCacheSize to verify that 
overwriting a cached entry (small → large → small) keeps totalCacheSize aligned 
with the current entry size.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/RATIS-2701
   
   ## How was this patch tested?
   
   Unit Test
   
   This PR is assisted by Cursor.


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