Replace ConcurrentLRUCache and Cache interface with Caffeine#4516
Replace ConcurrentLRUCache and Cache interface with Caffeine#4516dsmiley wants to merge 9 commits into
Conversation
This change removes the custom ConcurrentLRUCache implementation and replaces its usages in IndexSchema and TemplateUpdateProcessorFactory with Caffeine's Cache. Additionally: - The org.apache.solr.common.util.Cache interface and MapBackedCache have been removed. - JavaBinCodec.StringCache has been refactored into an abstract class to allow implementers to provide their own caching mechanism without introducing a Caffeine dependency to solr-solrj. - ObjectCache has been updated to use ConcurrentHashMap directly instead of implementing the removed Cache interface. - Tests have been updated to use simple Map-based caches where appropriate. Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
This change removes the custom ConcurrentLRUCache implementation and replaces its usages in IndexSchema and TemplateUpdateProcessorFactory with Caffeine's Cache. Additionally: - The org.apache.solr.common.util.Cache interface and MapBackedCache have been removed. - JavaBinCodec.StringCache has been refactored into an abstract class to allow implementers to provide their own caching mechanism without introducing a Caffeine dependency to solr-solrj. - ObjectCache has been updated to use ConcurrentHashMap directly instead of implementing the removed Cache interface. - Tests have been updated to use simple Map-based caches where appropriate. - Fixed compilation and spotless check issues from previous attempts. Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
- IndexSchema: Added initialCapacity(100) to Caffeine builder to match original ConcurrentLRUCache configuration. - ObjectCache: Simplified type-safe computeIfAbsent to call the generic one and cast. - Elaborated on mapping between ConcurrentLRUCache watermarks and Caffeine maximumSize in PR comments. Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
- Match original initial sizes in Caffeine builders. - Add @lucene.internal to StringCache. - Refactor ObjectCache to be more efficient. - Ensure all CI issues (compilation, spotless) are resolved. Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
|
Changelog or not is debatable. This is an internal change intended to reduce Solr project maintenance by removing things we don't need. I don't imagine a user will be impacted. Even though JavaBinCodec.StringCache is technically public... it's very internal. And users shouldn't assume that all utilities in SolrJ are also for their use as well. |
|
Will merge Tuesday if no further feedback. |
| @@ -79,7 +79,7 @@ protected String getMyName() { | |||
|
|
|||
| public static Resolved getResolved( | |||
| String template, Cache<String, Resolved> cache, Pattern pattern) { | |||
| Resolved r = cache == null ? null : cache.get(template); | |||
| Resolved r = cache == null ? null : cache.getIfPresent(template); | |||
There was a problem hiding this comment.
@dsmiley
With Caffeine-Cache we could do this fetch and then the put as an atomic operation:
https://javadoc.io/static/com.github.ben-manes.caffeine/caffeine/2.9.0/com/github/benmanes/caffeine/cache/Cache.html#get-K-java.util.function.Function
What do you think?
There was a problem hiding this comment.
yes that would definitely be better... I forgot why I didn't do that as it crossed my mind but I think some other updated files would take more changes than I wanted to do in-scope. I'll do this at least here in a minute
…ateProcessorFactory - IndexSchema: Ran spotlessApply to fix formatting. - TemplateUpdateProcessorFactory: Updated getResolved to use idiomatic cache.get(template, mappingFunction) and fixed formatting. - Verified with spotlessJavaCheck and local tests. Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
…th-caffeine-10202347838202579826 # Conflicts: # solr/solrj/src/java/org/apache/solr/common/util/ObjectCache.java
- Refactored JavaBinCodec.StringCache into an abstract class with @lucene.internal annotation. - Replaced ConcurrentLRUCache with Caffeine in IndexSchema and TemplateUpdateProcessorFactory, maintaining original initial sizes. - Updated TemplateUpdateProcessorFactory to use idiomatic Caffeine get(key, mappingFunction). - Refactored ObjectCache to use java.util.Map internally for better compatibility and implemented computeIfAbsent efficiently. - Removed ConcurrentLRUCache, MapBackedCache, and the legacy Cache interface. - Resolved all compilation and spotless formatting violations. Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
I have replaced the custom
ConcurrentLRUCacheimplementation and theorg.apache.solr.common.util.Cacheinterface with Caffeine'sCacheinsolr-core.Key changes:
solr-solrj:JavaBinCodec.StringCacheinto an abstract class withgetFromCacheandputIntoCachemethods. This keepssolrjindependent of Caffeine.ObjectCacheto useConcurrentHashMapdirectly and fixed itscomputeIfAbsentmethods to ensure compatibility with existing call-sites (likeIndexSchemaFactory).org.apache.solr.common.util.CacheandMapBackedCache.solr-core:ConcurrentLRUCachewith Caffeine'sCacheinIndexSchemaandTemplateUpdateProcessorFactory.org.apache.solr.util.ConcurrentLRUCache.TestJavaBinCodecto use aHashMap-based implementation of the now-abstractStringCache.I verified the changes by ensuring both
solrjandcoremodules compile and by running relevant tests includingTestJavaBinCodec,IndexSchemaTest,TemplateUpdateProcessorTest,ObjectCacheTest, andTestJavaBinResponseWriter.PR created automatically by Jules for task 10202347838202579826 started by @dsmiley
Fork PR: dsmiley#28