Skip to content

Commit

Permalink
Some refactoring to minimize changes to SolrCore
Browse files Browse the repository at this point in the history
  • Loading branch information
patsonluk committed Apr 18, 2024
1 parent c69deb9 commit 5b7b8c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
26 changes: 7 additions & 19 deletions solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ 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,8 +790,7 @@ public SolrCore reload(ConfigSet coreConfig) throws IOException {
updateHandler,
solrDelPolicy,
currentCore,
true,
isSynthetic);
true);

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

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);
SolrCore(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet configSet) {
this(coreContainer, cd, configSet, null, null, null, null, false);
}

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

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

initSearcher(prev);

this.isSynthetic = isSynthetic;

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

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

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

this.ruleExpiryLock = new ReentrantLock();
this.snapshotDelLock = new ReentrantLock();
Expand Down Expand Up @@ -1266,7 +1254,7 @@ public void seedVersionBuckets() {
}

/** Set UpdateLog to buffer updates if the slice is in construction. */
private void bufferUpdatesIfConstructing(CoreDescriptor coreDescriptor) {
protected void bufferUpdatesIfConstructing(CoreDescriptor coreDescriptor) {

if (coreContainer != null && coreContainer.isZooKeeperAware()) {
if (reqHandlers.get("/get") == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.rest.RestManager;

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

public static SolrCoreProxy createAndRegisterProxy(
public static SyntheticSolrCore createAndRegisterCore(
CoreContainer coreContainer, String syntheticCollectionName, String configSetName) {
Map<String, String> coreProps = new HashMap<>();
coreProps.put(CoreAdminParams.CORE_NODE_NAME, coreContainer.getHostName());
Expand All @@ -27,10 +30,20 @@ public static SolrCoreProxy createAndRegisterProxy(
ConfigSet coreConfig =
coreContainer.getConfigSetService().loadConfigSet(syntheticCoreDescriptor, configSetName);
syntheticCoreDescriptor.setConfigSetTrusted(coreConfig.isTrusted());
SolrCoreProxy syntheticCore =
new SolrCoreProxy(coreContainer, syntheticCoreDescriptor, coreConfig);
SyntheticSolrCore syntheticCore =
new SyntheticSolrCore(coreContainer, syntheticCoreDescriptor, coreConfig);
coreContainer.registerCore(syntheticCoreDescriptor, syntheticCore, false, false);

return syntheticCore;
}

@Override
protected void bufferUpdatesIfConstructing(CoreDescriptor coreDescriptor) {
//no updates to SyntheticSolrCore
}

@Override
protected RestManager initRestManager() throws SolrException {
return new RestManager(); //TODO explain why we cannot use the super class init routine
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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.core.SyntheticSolrCore;
import org.apache.solr.request.DelegatingSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.slf4j.Logger;
Expand Down Expand Up @@ -87,8 +87,8 @@ public static SolrCore getCore(
String syntheticCollectionName = getSyntheticCollectionName(confName);

CoreContainer coreContainer = solrCall.cores;
SolrCoreProxy syntheticCore =
SolrCoreProxy.createAndRegisterProxy(
SyntheticSolrCore syntheticCore =
SyntheticSolrCore.createAndRegisterCore(
coreContainer, syntheticCollectionName, coll.getConfigName());

// after this point the sync core should be available in the container. Double check
Expand Down

0 comments on commit 5b7b8c1

Please sign in to comment.