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

This commit is contained in:
Andrzej Bialecki 2019-05-14 14:09:24 +02:00
parent 13d1c113c1
commit 6f309dfa66
1 changed files with 10 additions and 1 deletions

View File

@ -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