You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2015/04/12 15:27:46 UTC
svn commit: r1673008 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/CHANGES.txt solr/core/
solr/core/src/java/org/apache/solr/core/PluginBag.java
solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
Author: noble
Date: Sun Apr 12 13:27:45 2015
New Revision: 1673008
URL: http://svn.apache.org/r1673008
Log:
SOLR-7380: SearchHandler should not try to load runtime components in inform()
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/PluginBag.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1673008&r1=1673007&r2=1673008&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Sun Apr 12 13:27:45 2015
@@ -54,6 +54,8 @@ Bug Fixes
* SOLR-7369: AngularJS UI insufficient URLDecoding in cloud/tree view (janhoy)
+* SOLR-7380: SearchHandler should not try to load runtime components in inform() (Noble Paul)
+
Optimizations
----------------------
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/PluginBag.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/PluginBag.java?rev=1673008&r1=1673007&r2=1673008&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/PluginBag.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/PluginBag.java Sun Apr 12 13:27:45 2015
@@ -21,8 +21,10 @@ package org.apache.solr.core;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -99,6 +101,16 @@ public class PluginBag<T> implements Aut
}
+ /**
+ * Check if any of the mentioned names are missing. If yes, return the Set of missing names
+ */
+ public Set<String> checkContains(Collection<String> names) {
+ if (names == null || names.isEmpty()) return Collections.EMPTY_SET;
+ HashSet<String> result = new HashSet<>();
+ for (String s : names) if (!this.registry.containsKey(s)) result.add(s);
+ return result;
+ }
+
PluginHolder<T> createPlugin(PluginInfo info) {
if ("true".equals(String.valueOf(info.attributes.get("runtimeLib")))) {
log.info(" {} : '{}' created with runtimeLib=true ", meta.getCleanTag(), info.name);
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java?rev=1673008&r1=1673007&r2=1673008&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java Sun Apr 12 13:27:45 2015
@@ -20,8 +20,10 @@ package org.apache.solr.handler.componen
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import org.apache.lucene.index.ExitableDirectoryReader;
import org.apache.lucene.util.Version;
@@ -33,6 +35,7 @@ import org.apache.solr.common.params.Mod
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CloseHook;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrCore;
@@ -71,6 +74,7 @@ public class SearchHandler extends Reque
protected List<SearchComponent> components = null;
private ShardHandlerFactory shardHandlerFactory ;
private PluginInfo shfInfo;
+ private SolrCore core;
protected List<String> getDefaultComponents()
{
@@ -106,6 +110,38 @@ public class SearchHandler extends Reque
@SuppressWarnings("unchecked")
public void inform(SolrCore core)
{
+ this.core = core;
+ Set<String> missing = new HashSet<>();
+ List<String> c = (List<String>) initArgs.get(INIT_COMPONENTS);
+ missing.addAll(core.getSearchComponents().checkContains(c));
+ List<String> first = (List<String>) initArgs.get(INIT_FIRST_COMPONENTS);
+ missing.addAll(core.getSearchComponents().checkContains(first));
+ List<String> last = (List<String>) initArgs.get(INIT_LAST_COMPONENTS);
+ missing.addAll(core.getSearchComponents().checkContains(last));
+ if (!missing.isEmpty()) throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Missing SearchComponents named : " + missing);
+ if (c != null && (first != null || last != null)) throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "First/Last components only valid if you do not declare 'components'");
+
+ if (shfInfo == null) {
+ shardHandlerFactory = core.getCoreDescriptor().getCoreContainer().getShardHandlerFactory();
+ } else {
+ shardHandlerFactory = core.createInitInstance(shfInfo, ShardHandlerFactory.class, null, null);
+ core.addCloseHook(new CloseHook() {
+ @Override
+ public void preClose(SolrCore core) {
+ shardHandlerFactory.close();
+ }
+
+ @Override
+ public void postClose(SolrCore core) {
+ }
+ });
+ }
+
+ }
+
+ private void initComponents() {
Object declaredComponents = initArgs.get(INIT_COMPONENTS);
List<String> first = (List<String>) initArgs.get(INIT_FIRST_COMPONENTS);
List<String> last = (List<String>) initArgs.get(INIT_LAST_COMPONENTS);
@@ -136,7 +172,7 @@ public class SearchHandler extends Reque
}
// Build the component list
- components = new ArrayList<>( list.size() );
+ List<SearchComponent> components = new ArrayList<>(list.size());
DebugComponent dbgCmp = null;
for(String c : list){
SearchComponent comp = core.getSearchComponent( c );
@@ -151,30 +187,24 @@ public class SearchHandler extends Reque
components.add(dbgCmp);
log.debug("Adding debug component:" + dbgCmp);
}
- if(shfInfo ==null) {
- shardHandlerFactory = core.getCoreDescriptor().getCoreContainer().getShardHandlerFactory();
- } else {
- shardHandlerFactory = core.createInitInstance(shfInfo, ShardHandlerFactory.class, null, null);
- core.addCloseHook(new CloseHook() {
- @Override
- public void preClose(SolrCore core) {
- shardHandlerFactory.close();
- }
- @Override
- public void postClose(SolrCore core) {
- }
- });
- }
-
+ this.components = components;
}
public List<SearchComponent> getComponents() {
+ if (components == null) {
+ synchronized (this) {
+ if (components == null) {
+ initComponents();
+ }
+ }
+ }
return components;
}
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{
+ if (components == null) getComponents();
ResponseBuilder rb = new ResponseBuilder(req, rsp, components);
if (rb.requestInfo != null) {
rb.requestInfo.setResponseBuilder(rb);