Skip to content

Commit

Permalink
Refactoring to avoid modifying existing method modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
patsonluk committed Feb 26, 2024
1 parent 9302830 commit 959ab57
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 40 deletions.
3 changes: 1 addition & 2 deletions solr/core/src/java/org/apache/solr/core/CoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,7 @@ public CoresLocator getCoresLocator() {
return coresLocator;
}

// TODO was protected, should go with new class approach
public SolrCore registerCore(
protected SolrCore registerCore(
CoreDescriptor cd, SolrCore core, boolean registerInZk, boolean skipRecovery) {
if (core == null) {
throw new RuntimeException("Can not register a null core.");
Expand Down
31 changes: 16 additions & 15 deletions solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
import org.apache.solr.search.facet.FacetParserFactory;
import org.apache.solr.search.stats.LocalStatsCache;
import org.apache.solr.search.stats.StatsCache;
import org.apache.solr.servlet.CoordinatorHttpSolrCall;
import org.apache.solr.update.DefaultSolrCoreState;
import org.apache.solr.update.DirectUpdateHandler2;
import org.apache.solr.update.IndexFingerprint;
Expand Down Expand Up @@ -206,6 +205,7 @@ public class SolrCore implements SolrInfoBean, Closeable {
private static final Logger slowLog =
LoggerFactory.getLogger(
MethodHandles.lookup().lookupClass().getName() + ".SlowRequest"); // nowarn
private final boolean isSynthetic;

private String name;

Expand Down Expand Up @@ -791,7 +791,8 @@ public SolrCore reload(ConfigSet coreConfig) throws IOException {
updateHandler,
solrDelPolicy,
currentCore,
true);
true,
isSynthetic);

// we open a new IndexWriter to pick up the latest config
core.getUpdateHandler().getSolrCoreState().newIndexWriter(core, false);
Expand Down Expand Up @@ -1053,9 +1054,13 @@ public CoreContainer getCoreContainer() {
return coreContainer;
}

// TODO was protected. a proper way will likely be creating a SolrCoreProxy class
public SolrCore(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet configSet) {
this(coreContainer, cd, configSet, null, null, null, null, false);
protected SolrCore(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet configSet) {
this(coreContainer, cd, configSet, false);
}

protected SolrCore(
CoreContainer coreContainer, CoreDescriptor cd, ConfigSet configSet, boolean isSynthetic) {
this(coreContainer, cd, configSet, null, null, null, null, false, isSynthetic);
}

private SolrCore(
Expand All @@ -1066,7 +1071,8 @@ private SolrCore(
UpdateHandler updateHandler,
IndexDeletionPolicyWrapper delPolicy,
SolrCore prev,
boolean reload) {
boolean reload,
boolean isSynthetic) {

// ensure that in unclean shutdown tests we still close this
assert ObjectReleaseTracker.track(searcherExecutor);
Expand Down Expand Up @@ -1176,8 +1182,10 @@ private SolrCore(

initSearcher(prev);

this.isSynthetic = isSynthetic;

// Initialize the RestManager
restManager = isSynthetic() ? new RestManager() : initRestManager();
restManager = isSynthetic ? new RestManager() : initRestManager();

// Finally tell anyone who wants to know
resourceLoader.inform(resourceLoader);
Expand All @@ -1204,7 +1212,7 @@ private SolrCore(
// searcher!
seedVersionBuckets();

if (!isSynthetic()) {
if (!isSynthetic) {
bufferUpdatesIfConstructing(coreDescriptor);
}

Expand Down Expand Up @@ -3099,13 +3107,6 @@ public void fetchLatestSchema() {
setLatestSchema(schema);
}

public final boolean isSynthetic() {
return coreDescriptor.getCollectionName() != null
&& coreDescriptor
.getCollectionName()
.startsWith(CoordinatorHttpSolrCall.SYNTHETIC_COLL_PREFIX);
}

public interface RawWriter {
default String getContentType() {
return BinaryResponseParser.BINARY_CONTENT_TYPE;
Expand Down
41 changes: 41 additions & 0 deletions solr/core/src/java/org/apache/solr/core/SolrCoreProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.apache.solr.core;

import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import org.apache.solr.common.params.CoreAdminParams;

public class SolrCoreProxy extends SolrCore {
public SolrCoreProxy(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet configSet) {
super(coreContainer, cd, configSet, true);
}

public static SolrCoreProxy createAndRegisterProxy(
CoreContainer coreContainer,
String syntheticCollectionName,
String configSetName,
String todo) {
Map<String, String> coreProps = new HashMap<>();
coreProps.put(CoreAdminParams.CORE_NODE_NAME, coreContainer.getHostName());
coreProps.put(CoreAdminParams.COLLECTION, syntheticCollectionName);

CoreDescriptor syntheticCoreDescriptor =
new CoreDescriptor(
syntheticCollectionName,
// todo,
Paths.get(coreContainer.getSolrHome() + "/" + syntheticCollectionName),
// Paths.get(coreContainer.getSolrHome() + "/" + todo),
coreProps,
coreContainer.getContainerProperties(),
coreContainer.getZkController());

ConfigSet coreConfig =
coreContainer.getConfigSetService().loadConfigSet(syntheticCoreDescriptor, configSetName);
syntheticCoreDescriptor.setConfigSetTrusted(coreConfig.isTrusted());
SolrCoreProxy syntheticCore =
new SolrCoreProxy(coreContainer, syntheticCoreDescriptor, coreConfig);
coreContainer.registerCore(syntheticCoreDescriptor, syntheticCore, false, false);

return syntheticCore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package org.apache.solr.servlet;

import java.lang.invoke.MethodHandles;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -32,11 +30,10 @@
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.core.ConfigSet;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrCoreProxy;
import org.apache.solr.request.DelegatingSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.slf4j.Logger;
Expand Down Expand Up @@ -79,29 +76,20 @@ public static SolrCore getCore(
ClusterState clusterState = zkStateReader.getClusterState();
DocCollection coll = clusterState.getCollectionOrNull(collectionName, true);

if (coll == null) { // querying on a non-existent collection, it could have been removed
log.info(
"Cannot find collection {} to proxy call to, it could have been deleted",
collectionName);
return null;
}
synchronized (CoordinatorHttpSolrCall.class) {
String confName = coll.getConfigName();
String syntheticCollectionName = getSyntheticCollectionName(confName);

CoreContainer coreContainer = solrCall.cores;
Map<String, String> coreProps = new HashMap<>();
coreProps.put(CoreAdminParams.CORE_NODE_NAME, coreContainer.getHostName());
coreProps.put(CoreAdminParams.COLLECTION, syntheticCollectionName);

CoreDescriptor syntheticCoreDescriptor =
new CoreDescriptor(
collectionName,
Paths.get(coreContainer.getSolrHome() + "/" + collectionName),
coreProps,
coreContainer.getContainerProperties(),
coreContainer.getZkController());

ConfigSet coreConfig =
coreContainer.getConfigSetService().loadConfigSet(syntheticCoreDescriptor, confName);
syntheticCoreDescriptor.setConfigSetTrusted(coreConfig.isTrusted());
SolrCore syntheticCore = new SolrCore(coreContainer, syntheticCoreDescriptor, coreConfig);

coreContainer.registerCore(syntheticCoreDescriptor, syntheticCore, false, false);
SolrCoreProxy syntheticCore =
SolrCoreProxy.createAndRegisterProxy(
coreContainer, syntheticCollectionName, coll.getConfigName(), collectionName);

// after this point the sync core should be available in the container. Double check
if (coreContainer.getCore(syntheticCore.getName()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public void testWatch() throws Exception {
// ensure querying throws exception
assertExceptionThrownWithMessageContaining(
SolrException.class,
List.of("Could not find collection"),
List.of("Collection not found"),
() ->
new QueryRequest(new SolrQuery("*:*"))
.setPreferredNodes(List.of(coordinatorJetty.getNodeName()))
Expand Down

0 comments on commit 959ab57

Please sign in to comment.