Skip to content

Commit

Permalink
SOLR-3746: Proper error reporting if updateLog is configured w/o nece…
Browse files Browse the repository at this point in the history
…ssary _version_ field in schema.xml (merge r1375674)

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/branch_4x@1375690 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
hossman committed Aug 21, 2012
1 parent 45b917c commit 20f7959
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
3 changes: 3 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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
----------------------
Expand Down
14 changes: 14 additions & 0 deletions solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,13 @@ private <T> T createInstance(String className, Class<T> cast, String msg) {
} 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);
}
}
Expand All @@ -502,6 +509,13 @@ private UpdateHandler createReloadedUpdateHandler(String className, String msg,
} 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);
}
}
Expand Down
38 changes: 37 additions & 1 deletion solr/core/src/java/org/apache/solr/update/VersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand All @@ -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<buckets.length; i++) {
Expand Down
15 changes: 15 additions & 0 deletions solr/core/src/test/org/apache/solr/core/TestBadConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ public void testUnsetSysProperty() throws Exception {
assertConfigs("bad_solrconfig.xml","schema.xml","unset.sys.property");
}

public void testUpdateLogButNoVersionField() throws Exception {

// :TODO: neccessary until SOLR-3699 is fixed
System.setProperty("solr.directoryFactory",
"org.apache.solr.core.SimpleFSDirectoryFactory");


System.setProperty("enable.update.log", "true");
try {
assertConfigs("solrconfig.xml", "schema12.xml", "_version_");
} finally {
System.clearProperty("enable.update.log");
}
}

public void testBogusScriptEngine() throws Exception {
// sanity check
Assume.assumeTrue(null == (new ScriptEngineManager()).getEngineByName("giberish"));
Expand Down

0 comments on commit 20f7959

Please sign in to comment.