SOLR-5227: Correctly fail schema init if a dynamicField is configured to be required, or have a default value

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1521587 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2013-09-10 19:00:52 +00:00
parent 315c0e6dbe
commit 88a00de5b7
6 changed files with 93 additions and 2 deletions

View File

@ -76,6 +76,14 @@ Upgrading from Solr 4.4.0
XXXXX and delete the ones that you do not wish to use. See SOLR-4953 &
SOLR-5108 for more details.
* In the past, schema.xml parsing would silently ignore "default" or "required"
options specified on <dynamicField/> declarations. Begining with 4.5, attempting
to do configured these on a dynamic field will cause an init error. If you
encounter one of these errors when upgrading an existing schema.xml, you can
safely remove these attributes, regardless of their value, from your config and
Solr will continue to bahave exactly as it did in previous versions. See
SOLR-5227 for more details.
* The UniqFieldsUpdateProcessorFactory has been improved to support all of the
FieldMutatingUpdateProcessorFactory selector options. The <lst named="fields">
init param option is now deprecated and should be replaced with the more standard
@ -201,6 +209,9 @@ Bug Fixes
* SOLR-4909: Use DirectoryReader.openIfChanged in non-NRT mode.
(Michael Garski via Robert Muir)
* SOLR-5227: Correctly fail schema initalization if a dynamicField is configured to
be required, or have a default value. (hossman)
Optimizations
----------------------

View File

@ -674,6 +674,14 @@ public class IndexSchema {
requiredFields.add(f);
}
} else if (node.getNodeName().equals(DYNAMIC_FIELD)) {
if( f.getDefaultValue() != null ) {
throw new SolrException(ErrorCode.SERVER_ERROR,
DYNAMIC_FIELD + " can not have a default value: " + name);
}
if ( f.isRequired() ) {
throw new SolrException(ErrorCode.SERVER_ERROR,
DYNAMIC_FIELD + " can not be required: " + name);
}
if (isValidFieldGlob(name)) {
// make sure nothing else has the same path
addDynamicField(dFields, f);

View File

@ -0,0 +1,34 @@
<?xml version="1.0" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<schema name="bad-schema-dynamicfield-default-val" version="1.4">
<types>
<fieldType name="string" class="solr.StrField"/>
</types>
<fields>
<field name="id" type="string" indexed="true" stored="true" />
<!-- BEGIN BAD STUFF -->
<dynamicField name="bad_*" type="string" default="BAD" />
<!-- END BAD STUFF -->
</fields>
<defaultSearchField>id</defaultSearchField>
<uniqueKey>id</uniqueKey>
</schema>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<schema name="bad-schema-dynamicfield-required" version="1.4">
<types>
<fieldType name="string" class="solr.StrField"/>
</types>
<fields>
<field name="id" type="string" indexed="true" stored="true" />
<!-- BEGIN BAD STUFF -->
<dynamicField name="bad_*" type="string" required="true" />
<!-- END BAD STUFF -->
</fields>
<defaultSearchField>id</defaultSearchField>
<uniqueKey>id</uniqueKey>
</schema>

View File

@ -41,8 +41,8 @@
<dynamicField name="*_pulsing" type="string_pulsing" indexed="true" stored="true"/>
<dynamicField name="*_standard" type="string_standard" indexed="true" stored="true"/>
<dynamicField name="*_disk" type="string_disk" indexed="false" stored="false" docValues="true" default="" />
<dynamicField name="*_memory" type="string_memory" indexed="false" stored="false" docValues="true" default="" />
<dynamicField name="*_disk" type="string_disk" indexed="false" stored="false" docValues="true" />
<dynamicField name="*_memory" type="string_memory" indexed="false" stored="false" docValues="true" />
</fields>
<defaultSearchField>string_f</defaultSearchField>
<uniqueKey>string_f</uniqueKey>

View File

@ -40,6 +40,10 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {
public void testSevereErrorsForDuplicateDynamicField() throws Exception {
doTest("bad-schema-dup-dynamicField.xml", "_twice");
}
public void testSevereErrorsForUnsupportedAttributesOnDynamicField() throws Exception {
doTest("bad-schema-dynamicfield-default-val.xml", "default");
doTest("bad-schema-dynamicfield-required.xml", "required");
}
public void testSevereErrorsForDuplicateFieldType() throws Exception {
doTest("bad-schema-dup-fieldType.xml", "ftAgain");