Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

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

Chris M. Hostetter71397bebd4b6
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0a1d576af3e..884de4b6964 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index 38a14e4da4e..48857c8ac1c 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -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;
}
diff --git a/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java b/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
index 53ea4e949c3..1a5a55bdbdc 100644
--- a/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
+++ b/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
@@ -116,6 +116,21 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
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 CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
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 CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
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 CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
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"),