dsmiley commented on code in PR #1243:
URL: https://github.com/apache/solr/pull/1243#discussion_r1066609153


##########
solr/core/src/java/org/apache/solr/core/TransientSolrCores.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.core;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/** A {@link SolrCores} that supports {@link CoreDescriptor#isTransient()}. */
+public class TransientSolrCores extends SolrCores {
+
+  protected final TransientSolrCoreCache transientSolrCoreCache;
+
+  public TransientSolrCores(CoreContainer container, int cacheSize) {
+    super(container);
+    transientSolrCoreCache = new TransientSolrCoreCacheDefault(this, 
cacheSize);
+  }
+
+  @Override
+  protected void close() {
+    super.close();
+    transientSolrCoreCache.close();
+  }
+
+  @Override
+  public void addCoreDescriptor(CoreDescriptor p) {
+    if (p.isTransient()) {
+      synchronized (modifyLock) {
+        getTransientCacheHandler().addTransientDescriptor(p.getName(), p);
+      }
+    } else {
+      super.addCoreDescriptor(p);
+    }
+  }
+
+  @Override
+  public void removeCoreDescriptor(CoreDescriptor p) {
+    if (p.isTransient()) {
+      synchronized (modifyLock) {
+        getTransientCacheHandler().removeTransientDescriptor(p.getName());
+      }
+    } else {
+      super.removeCoreDescriptor(p);
+    }
+  }
+
+  @Override
+  // Returns the old core if there was a core of the same name.
+  // WARNING! This should be the _only_ place you put anything into the list 
of transient cores!
+  public SolrCore putCore(CoreDescriptor cd, SolrCore core) {
+    if (cd.isTransient()) {
+      synchronized (modifyLock) {
+        addCoreDescriptor(cd); // cd must always be registered if we register 
a core
+        return getTransientCacheHandler().addCore(cd.getName(), core);
+      }
+    } else {
+      return super.putCore(cd, core);
+    }
+  }
+
+  @Override
+  public List<String> getLoadedCoreNames() {
+    synchronized (modifyLock) {
+      return distinctSetsUnion(

Review Comment:
   I pushed a change that did away with the distinctSetsUnion but did _not_ 
keep that optimization you have there on several lines.  I opted for simplicity 
over adding several lines and calling a particular metric name that isn't 
always obvious.  If you think the optimization is important, I can add it back 
in the way you did.



-- 
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: issues-unsubscr...@solr.apache.org

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