bruno-roustant commented on a change in pull request #147:
URL: https://github.com/apache/solr/pull/147#discussion_r639472680



##########
File path: 
solr/core/src/java/org/apache/solr/core/TransientSolrCoreCacheDefault.java
##########
@@ -18,103 +18,119 @@
 package org.apache.solr.core;
 
 import java.lang.invoke.MethodHandles;
-import java.util.*;
-
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
 import org.apache.solr.common.util.NamedList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Cache of the most frequently accessed transient cores. Keeps track of all 
the registered
+ * transient cores descriptors, including the cores in the cache as well as 
all the others.
+ */
 public class TransientSolrCoreCacheDefault extends TransientSolrCoreCache {
 
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-  private int cacheSize = 
NodeConfig.NodeConfigBuilder.DEFAULT_TRANSIENT_CACHE_SIZE;
-
-  protected CoreContainer coreContainer;
-
-  protected final Map<String, CoreDescriptor> transientDescriptors = new 
LinkedHashMap<>();
+  protected final CoreContainer coreContainer;
 
-  //WARNING! The _only_ place you put anything into the list of transient 
cores is with the putTransientCore method!
-  protected Map<String, SolrCore> transientCores = new LinkedHashMap<>(); // 
For "lazily loaded" cores
+  /**
+   * "Lazily loaded" cores cache with limited size. When the max size is 
reached, the least
+   * accessed core is evicted to make room for a new core.
+   * <p>Note about Caffeine cache stats:
+   * Since we are using {@link Cache#asMap()},
+   * {@link com.github.benmanes.caffeine.cache.stats.CacheStats} are not 
updated when we call
+   * any method of the Map view of the cache. This means
+   * {@link com.github.benmanes.caffeine.cache.stats.CacheStats} are not 
accurate and should
+   * not be used.
+   */
+  protected final Cache<String, SolrCore> transientCores;
 
   /**
-   * @param container The enclosing CoreContainer. It allows us to access 
everything we need.
+   * Unlimited map of all the descriptors for all the registered transient 
cores, including the
+   * cores in the {@link #transientCores} as well as all the others.
    */
-  public TransientSolrCoreCacheDefault(final CoreContainer container) {
-    this.coreContainer = container;
+  protected final Map<String, CoreDescriptor> transientDescriptors;
 
-    NodeConfig cfg = container.getNodeConfig();
-    if (cfg.getTransientCachePluginInfo() == null) {
-      // Still handle just having transientCacheSize defined in the body of 
solr.xml  not in a transient handler clause.
-      // deprecate this for 7.0?
-      this.cacheSize = cfg.getTransientCacheSize();
-    } else {
-      @SuppressWarnings({"rawtypes"})
-      NamedList args = cfg.getTransientCachePluginInfo().initArgs;
-      Object obj = args.get("transientCacheSize");
-      if (obj != null) {
-        this.cacheSize = (int) obj;
-      }
+  /**
+   * @param coreContainer The enclosing {@link CoreContainer}.
+   */
+  public TransientSolrCoreCacheDefault(CoreContainer coreContainer) {
+    this.coreContainer = coreContainer;
+
+    int cacheMaxSize = getConfiguredCacheMaxSize(coreContainer);
+    int initialCapacity = Math.min(cacheMaxSize, 1024);

Review comment:
       Ok, will do.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to