Skip to content

Apache Lucene open-source search software

SOLR-6647: Bad error message when missing resource from ZK when parsing Schema

Jan Høydahl7c3703a5b2d8
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index cbec9643c3e..90763906a9d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -262,6 +262,8 @@ Bug Fixes
* SOLR-6646: bin/solr start script fails to detect solr on non-default port and then after
30s tails wrong log file (janhoy)
+* SOLR-6647: Bad error message when missing resource from ZK when parsing Schema (janhoy)
+
Optimizations
----------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java b/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java
index efce8112aa9..122e4c39461 100644
--- a/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java
+++ b/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java
@@ -29,6 +29,7 @@ import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.SolrResourceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -84,4 +85,18 @@ public class CloudUtil {
}
}
}
+
+ /**
+ * Returns a displayable unified path to the given resource. For non-solrCloud that will be the
+ * same as getConfigDir, but for Cloud it will be getCollectionZkPath ending in a /
+ * <p/>
+ * <b>Note:</b> Do not use this to generate a valid file path, but for debug printing etc
+ * @param loader Resource loader instance
+ * @return a String of path to resource
+ */
+ public static String unifiedResourcePath(SolrResourceLoader loader) {
+ return (loader instanceof ZkSolrResourceLoader) ?
+ ((ZkSolrResourceLoader) loader).getCollectionZkPath() + "/" :
+ loader.getConfigDir();
+ }
}
diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
index 2df47bfc994..1cee8ac9b70 100644
--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
@@ -28,6 +28,7 @@ import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.uninverting.UninvertingReader;
import org.apache.lucene.util.Version;
+import org.apache.solr.cloud.CloudUtil;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.SolrParams;
@@ -445,7 +446,8 @@ public class IndexSchema {
}
protected void readSchema(InputSource is) {
- log.info("Reading Solr Schema from " + resourceName);
+ String resourcePath = CloudUtil.unifiedResourcePath(loader) + resourceName;
+ log.info("Reading Solr Schema from " + resourcePath);
try {
// pass the config resource loader to avoid building an empty one for no reason:
@@ -594,11 +596,11 @@ public class IndexSchema {
}
} catch (SolrException e) {
throw new SolrException(ErrorCode.getErrorCode(e.code()), e.getMessage() + ". Schema file is " +
- loader.getConfigDir() + resourceName, e);
+ resourcePath, e);
} catch(Exception e) {
// unexpected exception...
throw new SolrException(ErrorCode.SERVER_ERROR,
- "Schema Parsing Failed: " + e.getMessage() + ". Schema file is " + loader.getConfigDir() + resourceName,
+ "Schema Parsing Failed: " + e.getMessage() + ". Schema file is " + resourcePath,
e);
}