From 41c067bc1848cf2482a03b7da3dd03086e27c06e Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Tue, 21 Aug 2012 17:25:34 +0000 Subject: [PATCH] SOLR-3746: Proper error reporting if updateLog is configured w/o necessary _version_ field in schema.xml git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1375674 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 ++ .../java/org/apache/solr/core/SolrCore.java | 14 +++++++ .../org/apache/solr/update/VersionInfo.java | 38 ++++++++++++++++++- .../org/apache/solr/core/TestBadConfig.java | 15 ++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 7d7160d2f20..69d7e81903e 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -82,6 +82,9 @@ Bug Fixes conjunction with stored copyField targets by making real-time get never return copyField targets. (yonik) +* SOLR-3746: Proper error reporting if updateLog is configured w/o necessary + "_version_" field in schema.xml (hossman) + Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index 670972f8879..9c1082d8116 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -479,6 +479,13 @@ public final class SolrCore implements SolrInfoMBean { } catch (SolrException e) { throw e; } catch (Exception e) { + // The JVM likes to wrap our helpful SolrExceptions in things like + // "InvocationTargetException" that have no useful getMessage + if (null != e.getCause() && e.getCause() instanceof SolrException) { + SolrException inner = (SolrException) e.getCause(); + throw inner; + } + throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Error Instantiating "+msg+", "+className+ " failed to instantiate " +cast.getName(), e); } } @@ -502,6 +509,13 @@ public final class SolrCore implements SolrInfoMBean { } catch (SolrException e) { throw e; } catch (Exception e) { + // The JVM likes to wrap our helpful SolrExceptions in things like + // "InvocationTargetException" that have no useful getMessage + if (null != e.getCause() && e.getCause() instanceof SolrException) { + SolrException inner = (SolrException) e.getCause(); + throw inner; + } + throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Error Instantiating "+msg+", "+className+ " failed to instantiate " + UpdateHandler.class.getName(), e); } } diff --git a/solr/core/src/java/org/apache/solr/update/VersionInfo.java b/solr/core/src/java/org/apache/solr/update/VersionInfo.java index 65fa635ee59..8af574148ef 100644 --- a/solr/core/src/java/org/apache/solr/update/VersionInfo.java +++ b/solr/core/src/java/org/apache/solr/update/VersionInfo.java @@ -28,6 +28,7 @@ import org.apache.lucene.util.BitUtil; import org.apache.lucene.util.BytesRef; import org.apache.solr.common.SolrException; import org.apache.solr.core.SolrCore; +import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.SchemaField; import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.util.RefCounted; @@ -41,10 +42,45 @@ public class VersionInfo { private SchemaField idField; final ReadWriteLock lock = new ReentrantReadWriteLock(true); + /** + * Gets and returns the {@link #VERSION_FIELD} from the specified + * schema, after verifying that it is indexed, stored, and single-valued. + * If any of these pre-conditions are not met, it throws a SolrException + * with a user suitable message indicating the problem. + */ + public static SchemaField getAndCheckVersionField(IndexSchema schema) + throws SolrException { + final String errPrefix = VERSION_FIELD + "field must exist in schema, using indexed=\"true\" stored=\"true\" and multiValued=\"false\""; + SchemaField sf = schema.getFieldOrNull(VERSION_FIELD); + + if (null == sf) { + throw new SolrException + (SolrException.ErrorCode.SERVER_ERROR, + errPrefix + " (" + VERSION_FIELD + " does not exist)"); + } + if ( !sf.indexed() ) { + throw new SolrException + (SolrException.ErrorCode.SERVER_ERROR, + errPrefix + " (" + VERSION_FIELD + " is not indexed"); + } + if ( !sf.stored() ) { + throw new SolrException + (SolrException.ErrorCode.SERVER_ERROR, + errPrefix + " (" + VERSION_FIELD + " is not stored"); + } + if ( sf.multiValued() ) { + throw new SolrException + (SolrException.ErrorCode.SERVER_ERROR, + errPrefix + " (" + VERSION_FIELD + " is not multiValued"); + } + + return sf; + } + public VersionInfo(UpdateLog ulog, int nBuckets) { this.ulog = ulog; SolrCore core = ulog.uhandler.core; - versionField = core.getSchema().getFieldOrNull(VERSION_FIELD); + versionField = getAndCheckVersionField(core.getSchema()); idField = core.getSchema().getUniqueKeyField(); buckets = new VersionBucket[ BitUtil.nextHighestPowerOfTwo(nBuckets) ]; for (int i=0; i