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 2010/07/10 00:44:35 UTC
svn commit: r962714 - in /lucene/dev/trunk/solr: CHANGES.txt
src/java/org/apache/solr/core/CoreContainer.java
Author: hossman
Date: Fri Jul 9 22:44:35 2010
New Revision: 962714
URL: http://svn.apache.org/viewvc?rev=962714&view=rev
Log:
SOLR-1981: Solr will now fail correctly if solr.xml attempts to specify multiple cores that have the same name
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/src/java/org/apache/solr/core/CoreContainer.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=962714&r1=962713&r2=962714&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Fri Jul 9 22:44:35 2010
@@ -364,6 +364,8 @@ Bug Fixes
values which are Collections or other classes that implement
Iterable. (noble, hossman)
+* SOLR-1981: Solr will now fail correctly if solr.xml attempts to
+ specify multiple cores that have the same name (hossman)
Other Changes
----------------------
Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/core/CoreContainer.java?rev=962714&r1=962713&r2=962714&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/core/CoreContainer.java Fri Jul 9 22:44:35 2010
@@ -247,18 +247,40 @@ public class CoreContainer
SolrConfig.severeErrors.add(e);
SolrException.logOnce(log,null,e);
}
+
+ // before looping over each core, let's check the names and fail
+ // fast if the same one is reused multiple times.
+ { // local scope, won't need these vars again
+ NodeList nodes = (NodeList)cfg.evaluate("solr/cores/core/@name",
+ XPathConstants.NODESET);
+ Set<String> names = new HashSet<String>();
+ for (int i=0; i<nodes.getLength(); i++) {
+ String name = DOMUtil.getText(nodes.item(i));
+ if (names.contains(name)) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Multiple cores found with same name: " +
+ name);
+ }
+ names.add(name);
+ }
+ }
NodeList nodes = (NodeList)cfg.evaluate("solr/cores/core", XPathConstants.NODESET);
- boolean defaultCoreFound = false;
for (int i=0; i<nodes.getLength(); i++) {
Node node = nodes.item(i);
try {
String name = DOMUtil.getAttr(node, "name", null);
- if(name.equals(defaultCoreName)){
- if(defaultCoreFound) throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Only one 'DEFAULT_CORE' is allowed ");
- defaultCoreFound = true;
+ if (null == name) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Each core in solr.xml must have a 'name'");
+ }
+ if (name.equals(defaultCoreName)){
+ // for the default core we use a blank name,
+ // later on attempts to access it by it's full name will
+ // be mapped to this.
name="";
}
+
CoreDescriptor p = new CoreDescriptor(this, name, DOMUtil.getAttr(node, "instanceDir", null));
// deal with optional settings