Skip to content

ZOOKEEPER-4919: Make ResponseCache a LRU as it supposed to be#2243

Merged
kezhuw merged 5 commits intoapache:masterfrom
mikkosc:fix-lru-cache
Apr 19, 2025
Merged

ZOOKEEPER-4919: Make ResponseCache a LRU as it supposed to be#2243
kezhuw merged 5 commits intoapache:masterfrom
mikkosc:fix-lru-cache

Conversation

@mikkosc
Copy link
Copy Markdown
Contributor

@mikkosc mikkosc commented Apr 14, 2025

The ResponseCache has an inner class called LRUCache extends LinkedHashMap.
But the LinkedHashMap does not work as an LRU unless the third constructor argument is true.

This has basically reduced the caching to work as FIFO, if there are more than cache size elements to query then even popular items would have been dropped from the cache in FIFO insert order.

Added unit test that fails if the LRU cache is not working.

@kezhuw kezhuw changed the title Fix LRU cache ZOOKEEPER-4919: Make ResponseCache a LRU as it supposed to be Apr 19, 2025
Comment thread zookeeper-server/src/test/java/org/apache/zookeeper/test/ResponseCacheTest.java Outdated
Comment thread zookeeper-server/src/test/java/org/apache/zookeeper/test/ResponseCacheTest.java Outdated
Comment thread zookeeper-server/src/test/java/org/apache/zookeeper/test/ResponseCacheTest.java Outdated
@kezhuw kezhuw merged commit db8fe9c into apache:master Apr 19, 2025
16 checks passed
kezhuw pushed a commit that referenced this pull request Apr 19, 2025
Reviewers: tisonkun, kezhuw
Author: mikkosc
Closes #2243 from mikkosc/fix-lru-cache

(cherry picked from commit db8fe9c)
Signed-off-by: Kezhu Wang <kezhuw@apache.org>
kezhuw pushed a commit that referenced this pull request Apr 19, 2025
Reviewers: tisonkun, kezhuw
Author: mikkosc
Closes #2243 from mikkosc/fix-lru-cache

(cherry picked from commit db8fe9c)
Signed-off-by: Kezhu Wang <kezhuw@apache.org>
@kezhuw
Copy link
Copy Markdown
Member

kezhuw commented Apr 19, 2025

Merged and backported to 3.9 and 3.8 as it is a bug.

@mikkosc Thank you for your contribution! Do you have a jira account so I can assign ZOOKEEPER-4919 to you ?

@mikkosc
Copy link
Copy Markdown
Contributor Author

mikkosc commented Apr 21, 2025

Yes. It seems to be mikko / Mikko Tiihonen. I added comment to the jira to make it obvious

meszinorbi pushed a commit to meszinorbi/zookeeper-up that referenced this pull request Dec 10, 2025
Reviewers: tisonkun, kezhuw
Author: mikkosc
Closes apache#2243 from mikkosc/fix-lru-cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants