diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index bc7b7043312..71ecf3af8c6 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -574,6 +574,9 @@ Other Changes * SOLR-8277: (Search|Top)GroupsFieldCommand tweaks (Christine Poerschke) +* SOLR-8299: ConfigSet DELETE operation no longer allows deletion of config sets that + are currently in use by other collections (Anshum Gupta) + ================== 5.3.1 ================== Bug Fixes diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerConfigSetMessageHandler.java b/solr/core/src/java/org/apache/solr/cloud/OverseerConfigSetMessageHandler.java index f618fa03763..057a165c4cc 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerConfigSetMessageHandler.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerConfigSetMessageHandler.java @@ -46,9 +46,8 @@ import org.slf4j.LoggerFactory; import static org.apache.solr.cloud.OverseerMessageHandler.ExclusiveMarking.NONEXCLUSIVE; import static org.apache.solr.cloud.OverseerMessageHandler.ExclusiveMarking.NOTDETERMINED; -import static org.apache.solr.common.params.ConfigSetParams.ConfigSetAction.CREATE; -import static org.apache.solr.common.params.ConfigSetParams.ConfigSetAction.DELETE; import static org.apache.solr.common.params.CommonParams.NAME; +import static org.apache.solr.common.params.ConfigSetParams.ConfigSetAction.CREATE; /** * A {@link OverseerMessageHandler} that handles ConfigSets API related @@ -351,6 +350,12 @@ public class OverseerConfigSetMessageHandler implements OverseerMessageHandler { throw new SolrException(ErrorCode.BAD_REQUEST, "ConfigSet does not exist to delete: " + configSetName); } + for (String s : zkStateReader.getClusterState().getCollections()) { + if (configSetName.equals(zkStateReader.readConfigName(s))) + throw new SolrException(ErrorCode.BAD_REQUEST, + "Can not delete ConfigSet as it is currently being used by collection [" + s + "]"); + } + String propertyPath = ConfigSetProperties.DEFAULT_FILENAME; NamedList properties = getConfigSetProperties(getPropertyPath(configSetName, propertyPath)); if (properties != null) { diff --git a/solr/core/src/test/org/apache/solr/cloud/ConfigSetsAPITest.java b/solr/core/src/test/org/apache/solr/cloud/ConfigSetsAPITest.java new file mode 100644 index 00000000000..b31e9a0b00e --- /dev/null +++ b/solr/core/src/test/org/apache/solr/cloud/ConfigSetsAPITest.java @@ -0,0 +1,57 @@ +package org.apache.solr.cloud; + +/* + * 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. + */ + +import org.apache.lucene.util.LuceneTestCase; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.ConfigSetAdminRequest; +import org.apache.solr.common.SolrException; +import org.junit.Test; + +@LuceneTestCase.Slow +public class ConfigSetsAPITest extends AbstractFullDistribZkTestBase { + public ConfigSetsAPITest() { + super(); + sliceCount = 1; + } + + @Test + public void testConfigSetDeleteWhenInUse() throws Exception { + CollectionAdminRequest.Create create = new CollectionAdminRequest.Create(); + create.setConfigName("conf1"); + create.setCollectionName("test_configset_delete"); + create.setNumShards(1); + create.process(cloudClient); + waitForCollection(cloudClient.getZkStateReader(), "test_configset_delete", 1); + + ConfigSetAdminRequest.Delete deleteConfigRequest = new ConfigSetAdminRequest.Delete(); + deleteConfigRequest.setConfigSetName("conf1"); + try { + deleteConfigRequest.process(cloudClient); + fail("The config deletion should cause an exception as it's currently being used by a collection."); + } catch (SolrException e) { + // Do nothing + } + + // Clean up the collection + CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete(); + deleteCollectionRequest.setCollectionName("test_configset_delete"); + deleteCollectionRequest.process(cloudClient); + } + +}