Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-13454: Fix the method's behavior which caused test failures due to collections disappearing during iteration.

Andrzej Bialecki6f309dfa66bb
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 970d95d0d9f..9907b9cbae3 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
@@ -353,10 +353,19 @@ public class ClusterState implements JSONWriter.Writable {
public Map<String, CollectionRef> getCollectionStates() {
return immutableCollectionStates;
}
+
+ /**
+ * Iterate over collections. Unlike {@link #getCollectionStates()} collections passed to the
+ * consumer are guaranteed to exist.
+ * @param consumer collection consumer.
+ */
public void forEachCollection(Consumer<DocCollection> consumer) {
collectionStates.forEach((s, collectionRef) -> {
try {
- consumer.accept(collectionRef.get());
+ DocCollection collection = collectionRef.get();
+ if (collection != null) {
+ consumer.accept(collection);
+ }
} catch (SolrException e) {
if (e.getCause() instanceof KeeperException.NoNodeException) {
//don't do anything. This collection does not exist