You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2016/08/02 01:07:24 UTC
[04/40] lucene-solr:apiv2: SOLR-9323: Expose
ClusterSate.getCollectionStates which returns unverified list of collection
names
SOLR-9323: Expose ClusterSate.getCollectionStates which returns unverified list of collection names
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0ad365cb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0ad365cb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0ad365cb
Branch: refs/heads/apiv2
Commit: 0ad365cbd069230bc638684b30bc4dc338e3a66d
Parents: f8a99dc
Author: Noble Paul <no...@apache.org>
Authored: Fri Jul 22 13:56:58 2016 +0530
Committer: Noble Paul <no...@apache.org>
Committed: Fri Jul 22 13:56:58 2016 +0530
----------------------------------------------------------------------
.../org/apache/solr/handler/SQLHandler.java | 4 ++--
.../client/solrj/io/stream/CloudSolrStream.java | 25 ++++++++++----------
.../client/solrj/io/stream/TopicStream.java | 15 ++----------
.../apache/solr/common/cloud/ClusterState.java | 13 ++++++----
4 files changed, 24 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ad365cb/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/SQLHandler.java b/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
index 4031858..f83c43f 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 , Pe
CloudSolrClient 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);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ad365cb/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java
----------------------------------------------------------------------
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.java
index 8aba89c..2fb56ee 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);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ad365cb/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java
----------------------------------------------------------------------
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.java
index c4343c6..c8bf610 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);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ad365cb/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 55df271..3ab5a1f 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 {