You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2013/08/20 18:30:02 UTC

svn commit: r1515859 - in /lucene/dev/branches/branch_4x: ./ dev-tools/ lucene/ lucene/analysis/ lucene/analysis/icu/src/java/org/apache/lucene/collation/ lucene/backwards/ lucene/benchmark/ lucene/classification/ lucene/classification/src/ lucene/code...

Author: hossman
Date: Tue Aug 20 16:30:00 2013
New Revision: 1515859

URL: http://svn.apache.org/r1515859
Log:
SOLR-5108: fail plugin info loading if multiple instances exist but only one is expected (merge r1515852)

Added:
    lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-multiple-dirfactory.xml
      - copied unchanged from r1515852, lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-multiple-dirfactory.xml
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/dev-tools/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/BUILD.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/JRE_VERSION_MIGRATION.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/LICENSE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/MIGRATE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/README.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/SYSTEM_REQUIREMENTS.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationKeyFilterFactory.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_4x/lucene/benchmark/   (props changed)
    lucene/dev/branches/branch_4x/lucene/build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/ivy.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/src/   (props changed)
    lucene/dev/branches/branch_4x/lucene/codecs/   (props changed)
    lucene/dev/branches/branch_4x/lucene/common-build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.cfs.zip   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.nocfs.zip   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.cfs.zip   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.nocfs.zip   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSort.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortDocValues.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTotalHitCountCollector.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/demo/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/grouping/   (props changed)
    lucene/dev/branches/branch_4x/lucene/highlighter/   (props changed)
    lucene/dev/branches/branch_4x/lucene/ivy-settings.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/join/   (props changed)
    lucene/dev/branches/branch_4x/lucene/licenses/   (props changed)
    lucene/dev/branches/branch_4x/lucene/memory/   (props changed)
    lucene/dev/branches/branch_4x/lucene/misc/   (props changed)
    lucene/dev/branches/branch_4x/lucene/module-build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/queries/   (props changed)
    lucene/dev/branches/branch_4x/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQuerySort.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/queryparser/   (props changed)
    lucene/dev/branches/branch_4x/lucene/replicator/   (props changed)
    lucene/dev/branches/branch_4x/lucene/sandbox/   (props changed)
    lucene/dev/branches/branch_4x/lucene/site/   (props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_4x/lucene/suggest/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/tools/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/LICENSE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/README.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/SYSTEM_REQUIREMENTS.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/build.xml   (props changed)
    lucene/dev/branches/branch_4x/solr/cloud-dev/   (props changed)
    lucene/dev/branches/branch_4x/solr/common-build.xml   (props changed)
    lucene/dev/branches/branch_4x/solr/contrib/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrConfig.java
    lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-test-misc.xml
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestBadConfig.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestConfig.java   (props changed)
    lucene/dev/branches/branch_4x/solr/example/   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpclient-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpclient-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpcore-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpcore-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpmime-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpmime-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/scripts/   (props changed)
    lucene/dev/branches/branch_4x/solr/site/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/solr/webapp/   (props changed)

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1515859&r1=1515858&r2=1515859&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Tue Aug 20 16:30:00 2013
@@ -38,9 +38,10 @@ Upgrading from Solr 4.4.0
   would be chosen arbitrarily and silently.  Starting with 4.5, configuration 
   parsing will fail with an error in situations like this.  If you see error 
   messages such as "solrconfig.xml contains more than one value for config path: 
-  indexConfig/infoStream" check your solrconfig.xml file for multiple occurrences 
-  of "infoStream" and delete the one that you do not wish to use.  See SOLR-4953
-  for more details.
+  XXXXX" or "Found Z configuration sections when at most 1 is allowed matching 
+  expression: XXXXX" check your solrconfig.xml file for multiple occurrences of 
+  XXXXX and delete the ones that you do not wish to use.  See SOLR-4953 & 
+  SOLR-5108 for more details.
 
 Detailed Change List
 ----------------------
@@ -140,8 +141,9 @@ Other Changes
 
 * SOLR-4951: Better randomization of MergePolicy in Solr tests (hossman)
 
-* SOLR-4953: Make XML Configuration parsing fail if an xpath matches multiple 
-  nodes when only a single value is expected.  (hossman)
+* SOLR-4953, SOLR-5108: Make XML Configuration parsing fail if an xpath matches 
+  multiple nodes when only a single value or plugin instance is expected.  
+  (hossman)
 
 * The routing parameter "shard.keys" is deprecated as part of SOLR-5017 .The new parameter name is '_route_' .
   The old parameter should continue to work for another release  (Noble Paul)

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrConfig.java?rev=1515859&r1=1515858&r2=1515859&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrConfig.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrConfig.java Tue Aug 20 16:30:00 2013
@@ -17,6 +17,7 @@
 
 package org.apache.solr.core;
 
+import static org.apache.solr.core.SolrConfig.PluginOpts.*;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
 import org.apache.solr.schema.IndexSchemaFactory;
@@ -70,7 +71,15 @@ public class SolrConfig extends Config {
   
   public static final String DEFAULT_CONF_FILE = "solrconfig.xml";
 
-
+  static enum PluginOpts { 
+    MULTI_OK, 
+    REQUIRE_NAME,
+    REQUIRE_CLASS,
+    // EnumSet.of and/or EnumSet.copyOf(Collection) are anoying
+    // because of type determination
+    NOOP
+    }
+  
   /** Creates a default instance from the solrconfig.xml. */
   public SolrConfig()
   throws ParserConfigurationException, IOException, SAXException {
@@ -207,27 +216,46 @@ public class SolrConfig extends Config {
     }
      maxWarmingSearchers = getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
 
-     loadPluginInfo(SolrRequestHandler.class,"requestHandler",true, true);
-     loadPluginInfo(QParserPlugin.class,"queryParser",true, true);
-     loadPluginInfo(QueryResponseWriter.class,"queryResponseWriter",true, true);
-     loadPluginInfo(ValueSourceParser.class,"valueSourceParser",true, true);
-     loadPluginInfo(TransformerFactory.class,"transformer",true, true);
-     loadPluginInfo(SearchComponent.class,"searchComponent",true, true);
-     loadPluginInfo(QueryConverter.class,"queryConverter",true, true);
+     loadPluginInfo(SolrRequestHandler.class,"requestHandler",
+                    REQUIRE_NAME, REQUIRE_CLASS, MULTI_OK);
+     loadPluginInfo(QParserPlugin.class,"queryParser",
+                    REQUIRE_NAME, REQUIRE_CLASS, MULTI_OK);
+     loadPluginInfo(QueryResponseWriter.class,"queryResponseWriter",
+                    REQUIRE_NAME, REQUIRE_CLASS, MULTI_OK);
+     loadPluginInfo(ValueSourceParser.class,"valueSourceParser",
+                    REQUIRE_NAME, REQUIRE_CLASS, MULTI_OK);
+     loadPluginInfo(TransformerFactory.class,"transformer",
+                    REQUIRE_NAME, REQUIRE_CLASS, MULTI_OK);
+     loadPluginInfo(SearchComponent.class,"searchComponent",
+                    REQUIRE_NAME, REQUIRE_CLASS, MULTI_OK);
+
+     // TODO: WTF is up with queryConverter???
+     // it aparently *only* works as a singleton? - SOLR-4304
+     // and even then -- only if there is a single SpellCheckComponent
+     // because of queryConverter.setAnalyzer
+     loadPluginInfo(QueryConverter.class,"queryConverter",
+                    REQUIRE_NAME, REQUIRE_CLASS);
 
      // this is hackish, since it picks up all SolrEventListeners,
      // regardless of when/how/why they are used (or even if they are 
      // declared outside of the appropriate context) but there's no nice 
      // way around that in the PluginInfo framework
-     loadPluginInfo(SolrEventListener.class, "//listener",false, true);
+     loadPluginInfo(SolrEventListener.class, "//listener", 
+                    REQUIRE_CLASS, MULTI_OK);
 
-     loadPluginInfo(DirectoryFactory.class,"directoryFactory",false, true);
-     loadPluginInfo(IndexDeletionPolicy.class,indexConfigPrefix+"/deletionPolicy",false, true);
-     loadPluginInfo(CodecFactory.class,"codecFactory",false, false);
-     loadPluginInfo(IndexReaderFactory.class,"indexReaderFactory",false, true);
-     loadPluginInfo(UpdateRequestProcessorChain.class,"updateRequestProcessorChain",false, false);
-     loadPluginInfo(UpdateLog.class,"updateHandler/updateLog",false, false);
-     loadPluginInfo(IndexSchemaFactory.class,"schemaFactory",false, true);
+     loadPluginInfo(DirectoryFactory.class,"directoryFactory", 
+                    REQUIRE_CLASS);
+     loadPluginInfo(IndexDeletionPolicy.class,indexConfigPrefix+"/deletionPolicy", 
+                    REQUIRE_CLASS);
+     loadPluginInfo(CodecFactory.class,"codecFactory", 
+                    REQUIRE_CLASS);
+     loadPluginInfo(IndexReaderFactory.class,"indexReaderFactory", 
+                    REQUIRE_CLASS);
+     loadPluginInfo(UpdateRequestProcessorChain.class,"updateRequestProcessorChain", 
+                    MULTI_OK);
+     loadPluginInfo(UpdateLog.class,"updateHandler/updateLog");
+     loadPluginInfo(IndexSchemaFactory.class,"schemaFactory", 
+                    REQUIRE_CLASS);
 
      updateHandlerInfo = loadUpdatehandlerInfo();
 
@@ -245,8 +273,19 @@ public class SolrConfig extends Config {
             getBool("updateHandler/commitWithin/softCommit",true));
   }
 
-  private void loadPluginInfo(Class clazz, String tag, boolean requireName, boolean requireClass) {
+  private void loadPluginInfo(Class clazz, String tag, PluginOpts... opts) {
+    EnumSet<PluginOpts> options = EnumSet.<PluginOpts>of(NOOP, opts);
+    boolean requireName = options.contains(REQUIRE_NAME);
+    boolean requireClass = options.contains(REQUIRE_CLASS);
+
     List<PluginInfo> result = readPluginInfos(tag, requireName, requireClass);
+
+    if (1 < result.size() && ! options.contains(MULTI_OK)) {
+        throw new SolrException
+          (SolrException.ErrorCode.SERVER_ERROR,
+           "Found " + result.size() + " configuration sections when at most "
+           + "1 is allowed matching expression: " + tag);
+    }
     if(!result.isEmpty()) pluginStore.put(clazz.getName(),result);
   }
 
@@ -446,7 +485,15 @@ public class SolrConfig extends Config {
   }
   public PluginInfo getPluginInfo(String  type){
     List<PluginInfo> result = pluginStore.get(type);
-    return result == null || result.isEmpty() ? null: result.get(0);
+    if (result == null || result.isEmpty()) {
+      return null;
+    }
+    if (1 == result.size()) {
+      return result.get(0);
+    }
+
+    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+                            "Multiple plugins configured for type: " + type);
   }
   
   private void initLibs() {

Modified: lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-test-misc.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-test-misc.xml?rev=1515859&r1=1515858&r2=1515859&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-test-misc.xml (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-test-misc.xml Tue Aug 20 16:30:00 2013
@@ -44,8 +44,6 @@
   <lib dir="../../lib-dirs/c" regex="c1" />
   <lib path="../../lib-dirs/d/d1/" />
   
-  <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>
-
   <!-- see TestConfig.testJavaProperty -->
   <propTest attr1="${solr.test.sys.prop1}-$${literal}"
             attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestBadConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestBadConfig.java?rev=1515859&r1=1515858&r2=1515859&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestBadConfig.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestBadConfig.java Tue Aug 20 16:30:00 2013
@@ -27,6 +27,10 @@ public class TestBadConfig extends Abstr
     assertConfigs("bad_solrconfig.xml","schema.xml","unset.sys.property");
   }
 
+  public void testMultipleDirectoryFactories() throws Exception {
+      assertConfigs("bad-solrconfig-multiple-dirfactory.xml", "schema12.xml",
+                    "directoryFactory");
+  }
   public void testMultipleIndexConfigs() throws Exception {
       assertConfigs("bad-solrconfig-multiple-indexconfigs.xml", "schema12.xml",
                     "indexConfig");