fix: add missing lock protection for LRU cache policy #2860
fix: add missing lock protection for LRU cache policy #2860DongDongJu merged 4 commits intoLMCache:devfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical race condition affecting the LRU cache policy's update mechanism. By strategically relocating the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
…kend Signed-off-by: syaojun <libevent@yeah.net>
There was a problem hiding this comment.
Code Review
The pull request correctly addresses a potential race condition by moving the cache_policy.update_on_put call inside the if evict_success: block. This ensures that the cache policy's internal state is updated only when a cache item is successfully put, preventing inconsistencies if the put operation fails due to eviction issues. This is a good improvement for the correctness and robustness of the cache management logic.
| all_evict_keys.extend(evict_keys) | ||
| if evict_success: | ||
| self.current_cache_size += required_size | ||
| self.cache_policy.update_on_put(key) |
There was a problem hiding this comment.
The change correctly places self.cache_policy.update_on_put(key) within the if evict_success: block. Previously, update_on_put would be called unconditionally (line 343 in the original code), even if the put operation failed due to insufficient space and no eviction candidates. This could lead to an inconsistent state where the cache policy's internal tracking (e.g., LRU timestamps) was updated for an item that was never actually stored. The current placement ensures that the cache policy is updated only when the item is successfully added to the cache, maintaining data integrity and correctness.
DongDongJu
left a comment
There was a problem hiding this comment.
Thansk for the work!
fix: add missing lock protection for LRU cache policy in LocalDiskBackend Signed-off-by: syaojun <libevent@yeah.net>
fix: add missing lock protection for LRU cache policy in LocalDiskBackend Signed-off-by: syaojun <libevent@yeah.net>
What this PR does / why we need it:
Move update_on_put() call under disk_lock protection
Fix race conditions in chunk_hash_to_init_timestamp dictionary access by
ensuring proper lock protection for cache policy operations.
Special notes for your reviewers:
If applicable: