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/04/08 21:56:16 UTC
svn commit: r1465749 - in /lucene/dev/trunk/solr: CHANGES.txt
core/src/java/org/apache/solr/core/CoreContainer.java
core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
Author: hossman
Date: Mon Apr 8 19:56:16 2013
New Revision: 1465749
URL: http://svn.apache.org/r1465749
Log:
SOLR-4672: Requests attempting to use SolrCores which had init failures now result in 500 error responses with the details about the init failure, instead of 404 error responses
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1465749&r1=1465748&r2=1465749&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Apr 8 19:56:16 2013
@@ -200,6 +200,12 @@ Other Changes
Existing solr.xml files that do not have these options explicitly specified
should be updated accordingly. (hossman)
+* SOLR-4672: Requests attempting to use SolrCores which had init failures
+ (that would be reported by CoreAdmin STATUS requests) now result in 500
+ error responses with the details about the init failure, instead of 404
+ error responses. (hossman)
+
+
================== 4.2.1 ==================
Versions of Major Components
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java?rev=1465749&r1=1465748&r2=1465749&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java Mon Apr 8 19:56:16 2013
@@ -1138,10 +1138,13 @@ public class CoreContainer
}
}
}
- /** Gets a core by name and increase its refcount.
+ /**
+ * Gets a core by name and increase its refcount.
+ *
* @see SolrCore#close()
* @param name the core name
- * @return the core if found
+ * @return the core if found, null if a SolrCore by this name does not exist
+ * @exception SolrException if a SolrCore with this name failed to be initialized
*/
public SolrCore getCore(String name) {
@@ -1157,6 +1160,16 @@ public class CoreContainer
// OK, it's not presently in any list, is it in the list of dynamic cores but not loaded yet? If so, load it.
CoreDescriptor desc = coreMaps.getDynamicDescriptor(name);
if (desc == null) { //Nope, no transient core with this name
+
+ // if there was an error initalizing this core, throw a 500
+ // error with the details for clients attempting to access it.
+ Exception e = getCoreInitFailures().get(name);
+ if (null != e) {
+ throw new SolrException(ErrorCode.SERVER_ERROR, "SolrCore '" + name +
+ "' is not available due to init failure: " +
+ e.getMessage(), e);
+ }
+ // otherwise the user is simply asking for something that doesn't exist.
return null;
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java?rev=1465749&r1=1465748&r2=1465749&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java Mon Apr 8 19:56:16 2013
@@ -116,6 +116,21 @@ public class CoreContainerCoreInitFailur
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
0 < fail.getCause().getMessage().indexOf("bogus_path"));
+ // check that we get null accessing a non-existent core
+ assertNull(cc.getCore("does_not_exist"));
+ // check that we get a 500 accessing the core with an init failure
+ try {
+ SolrCore c = cc.getCore("bogus");
+ fail("Failed to get Exception on accessing core with init failure");
+ } catch (SolrException ex) {
+ assertEquals(500, ex.code());
+ // double wrapped
+ String cause = ex.getCause().getCause().getMessage();
+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
+ 0 < cause.indexOf("bogus_path"));
+
+ }
+
// let the test end here, with some recorded failures, and let cleanUp()
// verify that there is no problem shuting down CoreContainer with known
// SolrCore failures
@@ -167,6 +182,19 @@ public class CoreContainerCoreInitFailur
assertTrue("init failure doesn't mention problem: " + fail.getMessage(),
0 < fail.getMessage().indexOf("DummyMergePolicy"));
+ // check that we get null accessing a non-existent core
+ assertNull(cc.getCore("does_not_exist"));
+ // check that we get a 500 accessing the core with an init failure
+ try {
+ SolrCore c = cc.getCore("col_bad");
+ fail("Failed to get Exception on accessing core with init failure");
+ } catch (SolrException ex) {
+ assertEquals(500, ex.code());
+ // double wrapped
+ String cause = ex.getCause().getCause().getMessage();
+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
+ 0 < cause.indexOf("DummyMergePolicy"));
+ }
// -----
// "fix" the bad collection
@@ -217,6 +245,19 @@ public class CoreContainerCoreInitFailur
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
0 < fail.getCause().getMessage().indexOf("bogus_path"));
+ // check that we get null accessing a non-existent core
+ assertNull(cc.getCore("does_not_exist"));
+ // check that we get a 500 accessing the core with an init failure
+ try {
+ SolrCore c = cc.getCore("bogus");
+ fail("Failed to get Exception on accessing core with init failure");
+ } catch (SolrException ex) {
+ assertEquals(500, ex.code());
+ // double wrapped
+ String cause = ex.getCause().getCause().getMessage();
+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
+ 0 < cause.indexOf("bogus_path"));
+ }
// -----
// register bogus as an alias for col_ok and confirm failure goes away
@@ -281,7 +322,6 @@ public class CoreContainerCoreInitFailur
assertTrue("init failure doesn't mention problem: " + fail.toString(),
0 < ((SAXParseException)fail).getSystemId().indexOf("solrconfig.xml"));
-
// ----
// fix col_bad's config (again) and RELOAD to fix failure
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-basic.xml"),