Apache Lucene open-source search software
SOLR-9323: Expose ClusterSate.getCollectionStates which returns unverified list of collection names
Noble Paul0ad365cbd069
diff --git a/solr/core/src/java/org/apache/solr/handler/SQLHandler.java b/solr/core/src/java/org/apache/solr/handler/SQLHandler.javaindex 403185838c9..f83c43f639d 100644--- a/solr/core/src/java/org/apache/solr/handler/SQLHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/SQLHandler.java@@ -1514,9 +1514,9 @@ public class SQLHandler extends RequestHandlerBase implements SolrCoreAware , PeCloudSolrClient cloudSolrClient = this.context.getSolrClientCache().getCloudSolrClient(this.zkHost);cloudSolrClient.connect();ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();- Map<String, DocCollection> collections = zkStateReader.getClusterState().getCollectionsMap();+ Set<String> collections = zkStateReader.getClusterState().getCollectionStates().keySet();if (collections.size() != 0) {- this.tables.addAll(collections.keySet());+ this.tables.addAll(collections);}Collections.sort(this.tables);}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.javaindex 8aba89c2e66..2fb56ee37b2 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java@@ -352,6 +352,16 @@ public class CloudSolrStream extends TupleStream implements Expressible {}}+ public static Collection<Slice> getSlicesIgnoreCase(String name, ClusterState clusterState) {+ for (String coll : clusterState.getCollectionStates().keySet()) {+ if (coll.equalsIgnoreCase(name)) {+ DocCollection collection = clusterState.getCollectionOrNull(coll);+ if (collection != null) return collection.getActiveSlices();+ }+ }+ return null;+ }+protected void constructStreams() throws IOException {try {@@ -362,20 +372,9 @@ public class CloudSolrStream extends TupleStream implements Expressible {//System.out.println("Connected to zk an got cluster state.");Collection<Slice> slices = clusterState.getActiveSlices(this.collection);-+ if (slices == null) slices = getSlicesIgnoreCase(this.collection, clusterState);if (slices == null) {- //Try case insensitive match- Map<String, DocCollection> collectionsMap = clusterState.getCollectionsMap();- for (Map.Entry<String, DocCollection> entry : collectionsMap.entrySet()) {- if (entry.getKey().equalsIgnoreCase(collection)) {- slices = entry.getValue().getActiveSlices();- break;- }- }-- if (slices == null) {- throw new Exception("Collection not found:" + this.collection);- }+ throw new Exception("Collection not found:" + this.collection);}ModifiableSolrParams mParams = new ModifiableSolrParams(params);diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.javaindex c4343c687e1..c8bf61048df 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java@@ -519,20 +519,9 @@ public class TopicStream extends CloudSolrStream implements Expressible {//System.out.println("Connected to zk an got cluster state.");Collection<Slice> slices = clusterState.getActiveSlices(this.collection);-+ if (slices == null) slices = getSlicesIgnoreCase(this.collection, clusterState);if (slices == null) {- //Try case insensitive match- Map<String, DocCollection> collectionsMap = clusterState.getCollectionsMap();- for (Map.Entry<String, DocCollection> entry : collectionsMap.entrySet()) {- if (entry.getKey().equalsIgnoreCase(collection)) {- slices = entry.getValue().getActiveSlices();- break;- }- }-- if (slices == null) {- throw new Exception("Collection not found:" + this.collection);- }+ throw new Exception("Collection not found:" + this.collection);}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 55df27189bd..3ab5a1f8c1a 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@@ -39,8 +39,8 @@ import org.noggit.JSONWriter;public class ClusterState implements JSONWriter.Writable {private final Integer znodeVersion;-- private final Map<String, CollectionRef> collectionStates;++ private final Map<String, CollectionRef> collectionStates, immutableCollectionStates;private Set<String> liveNodes;/**@@ -67,6 +67,7 @@ public class ClusterState implements JSONWriter.Writable {this.liveNodes = new HashSet<>(liveNodes.size());this.liveNodes.addAll(liveNodes);this.collectionStates = new LinkedHashMap<>(collectionStates);+ this.immutableCollectionStates = Collections.unmodifiableMap(collectionStates);}@@ -432,10 +433,12 @@ public class ClusterState implements JSONWriter.Writable {this.liveNodes = liveNodes;}- /**For internal use only+ /** Be aware that this may return collections which may not exist now.+ * You can confirm that this collection exists after verifying+ * CollectionRef.get() != null*/- Map<String, CollectionRef> getCollectionStates() {- return collectionStates;+ public Map<String, CollectionRef> getCollectionStates() {+ return immutableCollectionStates;}public static class CollectionRef {