Apache Lucene open-source search software
SOLR-11157: remove-policy must fail if a policy to be deleted is used by a collection
Noble Paul82a426c6e78b
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.javaindex 65bd81b80d4..119b0389d10 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;