You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2017/07/31 14:05:15 UTC
lucene-solr:branch_7x: SOLR-11157: remove-policy must fail if a
policy to be deleted is used by a collection
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x 98f900943 -> d81c56377
SOLR-11157: remove-policy must fail if a policy to be deleted is used by a collection
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/d81c5637
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d81c5637
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d81c5637
Branch: refs/heads/branch_7x
Commit: d81c56377aaa84c2607b725787a0f91a329fceea
Parents: 98f9009
Author: Noble Paul <no...@apache.org>
Authored: Mon Jul 31 23:35:06 2017 +0930
Committer: Noble Paul <no...@apache.org>
Committed: Mon Jul 31 23:35:06 2017 +0930
----------------------------------------------------------------------
solr/CHANGES.txt | 2 ++
.../cloud/autoscaling/AutoScalingHandler.java | 4 ++++
.../autoscaling/AutoScalingHandlerTest.java | 21 ++++++++++++++++++++
.../apache/solr/common/cloud/ClusterState.java | 15 ++++++++++++++
4 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d81c5637/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 2232b55..c7c3243 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -103,6 +103,8 @@ Other Changes
* SOLR-11131: Document 'assert' as a command option in bin/solr, and bin/solr.cmd scripts.
(Jason Gerlowski via Anshum Gupta)
+* SOLR-11157: remove-policy must fail if a policy to be deleted is used by a collection (noble)
+
================== 7.0.0 ==================
Versions of Major Components
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d81c5637/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
index 356ce37..b9bed3d 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
@@ -193,6 +193,10 @@ public class AutoScalingHandler extends RequestHandlerBase implements Permission
if (policies == null || !policies.containsKey(policyName)) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No policy exists with name: " + policyName);
}
+ container.getZkController().getZkStateReader().getClusterState().forEachCollection(coll -> {
+ if (policyName.equals(coll.getPolicyName())) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+ StrUtils.formatString("policy : {0} is being used by collection {1}", policyName, coll.getName()));
+ });
zkSetPolicies(container.getZkController().getZkStateReader(), policyName, null);
rsp.getValues().add("result", "success");
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d81c5637/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
index 197801a..6ac35dd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
@@ -287,6 +287,27 @@ public class AutoScalingHandlerTest extends SolrCloudTestCase {
}
}
+ @Test
+ public void testDeleteUsedPolicy() throws Exception {
+ CloudSolrClient solrClient = cluster.getSolrClient();
+ // add multiple policies
+ String setPolicyCommand = "{'set-policy': {" +
+ " 'nodelete':[" +
+ " {'nodeRole':'overseer', 'replica':0}]}}";
+ solrClient.request(createAutoScalingRequest(SolrRequest.METHOD.POST, setPolicyCommand));
+ CollectionAdminRequest.createCollection("COLL1", "conf", 1, 1)
+ .setPolicy("nodelete")
+ .process(cluster.getSolrClient());
+ String removePolicyCommand = "{remove-policy : nodelete}";
+ createAutoScalingRequest(SolrRequest.METHOD.POST, removePolicyCommand);
+ try {
+ solrClient.request(createAutoScalingRequest(SolrRequest.METHOD.POST, removePolicyCommand));
+ fail("should have failed");
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("is being used by collection"));
+ }
+ solrClient.request(CollectionAdminRequest.deleteCollection("COLL1"));
+ }
public static SolrRequest createAutoScalingRequest(SolrRequest.METHOD m, String message) {
return createAutoScalingRequest(m, null, message);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d81c5637/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
index 65bd81b..119b038 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
@@ -25,10 +25,12 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.util.Utils;
+import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.Watcher;
import org.noggit.JSONWriter;
@@ -444,7 +446,20 @@ public class ClusterState implements JSONWriter.Writable {
public Map<String, CollectionRef> getCollectionStates() {
return immutableCollectionStates;
}
+ public void forEachCollection(Consumer<DocCollection> consumer) {
+ collectionStates.forEach((s, collectionRef) -> {
+ try {
+ consumer.accept(collectionRef.get());
+ } catch (SolrException e) {
+ if (e.getCause() instanceof KeeperException.NoNodeException) {
+ //don't do anything. This collection does not exist
+ } else{
+ throw e;
+ }
+ }
+ });
+ }
public static class CollectionRef {
protected final AtomicInteger gets = new AtomicInteger();
private final DocCollection coll;