diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 733fcd5b863..0d21c670b2a 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -242,6 +242,8 @@ Bug Fixes * SOLR-7666: Many small fixes to Angular UI (Upayavira, Alexandre Rafalovitch) +* SOLR-7967: AddSchemaFieldsUpdateProcessorFactory does not check if the ConfigSet is immutable (Gregory Chanan) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactory.java index e7ce92887e5..d388e7e91e6 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactory.java +++ b/solr/core/src/java/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactory.java @@ -47,6 +47,7 @@ import java.util.Set; import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST; import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR; +import static org.apache.solr.core.ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG; /** @@ -290,6 +291,9 @@ public class AddSchemaFieldsUpdateProcessorFactory extends UpdateRequestProcesso // nothing to do - no fields will be added - exit from the retry loop log.debug("No fields to add to the schema."); break; + } else if ( isImmutableConfigSet(core) ) { + final String message = "This ConfigSet is immutable."; + throw new SolrException(BAD_REQUEST, message); } if (log.isDebugEnabled()) { StringBuilder builder = new StringBuilder(); @@ -399,5 +403,11 @@ public class AddSchemaFieldsUpdateProcessorFactory extends UpdateRequestProcesso } return selector; } + + private boolean isImmutableConfigSet(SolrCore core) { + NamedList args = core.getConfigSetProperties(); + Object immutable = args != null ? args.get(IMMUTABLE_CONFIGSET_ARG) : null; + return immutable != null ? Boolean.parseBoolean(immutable.toString()) : false; + } } } diff --git a/solr/core/src/test/org/apache/solr/core/TestConfigSetImmutable.java b/solr/core/src/test/org/apache/solr/core/TestConfigSetImmutable.java index 02e48770dd7..6347ae1eafd 100644 --- a/solr/core/src/test/org/apache/solr/core/TestConfigSetImmutable.java +++ b/solr/core/src/test/org/apache/solr/core/TestConfigSetImmutable.java @@ -23,6 +23,8 @@ import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.client.solrj.impl.XMLResponseParser; +import org.apache.solr.common.util.NamedList; import org.apache.solr.util.RestTestBase; import org.junit.After; import org.junit.Before; @@ -48,9 +50,8 @@ public class TestConfigSetImmutable extends RestTestBase { FileUtils.write(new File(tmpConfDir, "configsetprops.json"), new StringBuilder("{\"immutable\":\"true\"}")); System.setProperty("managed.schema.mutable", "true"); - System.setProperty("enable.update.log", "false"); - createJettyAndHarness(tmpSolrHome.getAbsolutePath(), "solrconfig-managed-schema.xml", "schema-rest.xml", + createJettyAndHarness(tmpSolrHome.getAbsolutePath(), "solrconfig-schemaless.xml", "schema-rest.xml", "/solr", true, null); } @@ -95,4 +96,24 @@ public class TestConfigSetImmutable extends RestTestBase { assertNotNull(map.get("errors")); assertTrue(map.get("errors").toString().contains("immutable")); } + + @Test + public void testAddSchemaFieldsImmutable() throws Exception { + final String error = "error"; + + // check writing an existing field is okay + String updateXMLSafe = "\"testdoc\""; + String response = restTestHarness.update(updateXMLSafe); + XMLResponseParser parser = new XMLResponseParser(); + NamedList listResponse = parser.processResponse(new StringReader(response)); + assertNull(listResponse.get(error)); + + // check writing a new field is not okay + String updateXMLNotSafe = "\"testdoc\"" + + "\"foobar\""; + response = restTestHarness.update(updateXMLNotSafe); + listResponse = parser.processResponse(new StringReader(response)); + assertNotNull(listResponse.get(error)); + assertTrue(listResponse.get(error).toString().contains("immutable")); + } }