From 5b372bd1cddfc200cd9c115a2fe286df2afbce32 Mon Sep 17 00:00:00 2001 From: Erick Erickson Date: Mon, 4 Nov 2013 23:21:12 +0000 Subject: [PATCH] Fix for SOLR-5418, merge after altering schema produces error git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1538802 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 + .../apache/solr/core/SchemaCodecFactory.java | 26 ++- .../collection1/conf/solrconfig-minimal.xml | 2 +- .../apache/solr/core/TestCodecSupport.java | 12 -- .../solr/schema/ChangedSchemaMergeTest.java | 148 ++++++++++++++++++ 5 files changed, 164 insertions(+), 27 deletions(-) create mode 100644 solr/core/src/test/org/apache/solr/schema/ChangedSchemaMergeTest.java diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index b6e72327004..e6b0c275c11 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -148,6 +148,9 @@ Bug Fixes work as intended for an alias spanning more than 1 collection. (Thomas Egense, Shawn Heisey, Mark Miller) +* SOLR-5418: Background merge after field removed from solr.xml causes error. + (Reported on user's list, Robert M's patch via Erick Erickson) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java b/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java index 7673131faa2..088375d00ac 100644 --- a/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java +++ b/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java @@ -54,25 +54,23 @@ public class SchemaCodecFactory extends CodecFactory implements SolrCoreAware { codec = new Lucene46Codec() { @Override public PostingsFormat getPostingsFormatForField(String field) { - final SchemaField fieldOrNull = core.getLatestSchema().getFieldOrNull(field); - if (fieldOrNull == null) { - throw new IllegalArgumentException("no such field " + field); - } - String postingsFormatName = fieldOrNull.getType().getPostingsFormat(); - if (postingsFormatName != null) { - return PostingsFormat.forName(postingsFormatName); + final SchemaField schemaField = core.getLatestSchema().getFieldOrNull(field); + if (schemaField != null) { + String postingsFormatName = schemaField.getType().getPostingsFormat(); + if (postingsFormatName != null) { + return PostingsFormat.forName(postingsFormatName); + } } return super.getPostingsFormatForField(field); } @Override public DocValuesFormat getDocValuesFormatForField(String field) { - final SchemaField fieldOrNull = core.getLatestSchema().getFieldOrNull(field); - if (fieldOrNull == null) { - throw new IllegalArgumentException("no such field " + field); - } - String docValuesFormatName = fieldOrNull.getType().getDocValuesFormat(); - if (docValuesFormatName != null) { - return DocValuesFormat.forName(docValuesFormatName); + final SchemaField schemaField = core.getLatestSchema().getFieldOrNull(field); + if (schemaField != null) { + String docValuesFormatName = schemaField.getType().getDocValuesFormat(); + if (docValuesFormatName != null) { + return DocValuesFormat.forName(docValuesFormatName); + } } return super.getDocValuesFormatForField(field); } diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-minimal.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-minimal.xml index 78a4eb711d3..26af3a7cf5b 100644 --- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-minimal.xml +++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-minimal.xml @@ -29,7 +29,7 @@ class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"/> - +