SOLR-5119: Managed schema problems after adding fields via Schema Rest API

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1513238 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2013-08-12 20:16:37 +00:00
parent 7a42fbecbd
commit d4c20941c9
3 changed files with 26 additions and 0 deletions

View File

@ -114,6 +114,9 @@ Bug Fixes
* SOLR-5121: zkcli usage help for makepath doesn't match actual command.
(Daniel Collins via Mark Miller)
* SOLR-5119: Managed schema problems after adding fields via Schema Rest API.
(Nils Kübler, Steve Rowe)
Optimizations
----------------------

View File

@ -390,6 +390,9 @@ public final class ManagedIndexSchema extends IndexSchema {
newSchema.uniqueKeyFieldName = uniqueKeyFieldName;
newSchema.uniqueKeyFieldType = uniqueKeyFieldType;
// After the schema is persisted, resourceName is the same as managedSchemaResourceName
newSchema.resourceName = managedSchemaResourceName;
if (includeFieldDataStructures) {
// These need new collections, since addFields() can add members to them
newSchema.fields.putAll(fields);

View File

@ -421,4 +421,24 @@ public class TestManagedSchema extends AbstractBadConfigTestBase {
assertNotNull(newNewSchema.getUniqueKeyField());
assertEquals("str", newNewSchema.getUniqueKeyField().getName());
}
public void testAddFieldThenReload() throws Exception {
deleteCore();
File managedSchemaFile = new File(tmpConfDir, "managed-schema");
assertTrue(managedSchemaFile.delete()); // Delete managed-schema so it won't block parsing a new schema
initCore("solrconfig-mutable-managed-schema.xml", "schema-one-field-no-dynamic-field.xml", tmpSolrHome.getPath());
String fieldName = "new_text_field";
assertNull("Field '" + fieldName + "' is present in the schema",
h.getCore().getLatestSchema().getFieldOrNull(fieldName));
Map<String,Object> options = new HashMap<String,Object>();
IndexSchema oldSchema = h.getCore().getLatestSchema();
String fieldType = "text";
SchemaField newField = oldSchema.newField(fieldName, fieldType, options);
IndexSchema newSchema = oldSchema.addField(newField);
h.getCore().setLatestSchema(newSchema);
h.reload();
}
}