SOLR-9323: Expose ClusterSate.getCollectionStates which returns unverified list of collection names

This commit is contained in:
Noble Paul 2016-07-22 13:56:58 +05:30
parent f8a99dc3c3
commit 0ad365cbd0
4 changed files with 24 additions and 33 deletions

View File

@ -1514,9 +1514,9 @@ public class SQLHandler extends RequestHandlerBase implements SolrCoreAware , Pe
CloudSolrClient cloudSolrClient = this.context.getSolrClientCache().getCloudSolrClient(this.zkHost); CloudSolrClient cloudSolrClient = this.context.getSolrClientCache().getCloudSolrClient(this.zkHost);
cloudSolrClient.connect(); cloudSolrClient.connect();
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader(); ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
Map<String, DocCollection> collections = zkStateReader.getClusterState().getCollectionsMap(); Set<String> collections = zkStateReader.getClusterState().getCollectionStates().keySet();
if (collections.size() != 0) { if (collections.size() != 0) {
this.tables.addAll(collections.keySet()); this.tables.addAll(collections);
} }
Collections.sort(this.tables); Collections.sort(this.tables);
} }

View File

@ -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 { protected void constructStreams() throws IOException {
try { try {
@ -362,21 +372,10 @@ public class CloudSolrStream extends TupleStream implements Expressible {
//System.out.println("Connected to zk an got cluster state."); //System.out.println("Connected to zk an got cluster state.");
Collection<Slice> slices = clusterState.getActiveSlices(this.collection); 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) { if (slices == null) {
throw new Exception("Collection not found:" + this.collection); throw new Exception("Collection not found:" + this.collection);
} }
}
ModifiableSolrParams mParams = new ModifiableSolrParams(params); ModifiableSolrParams mParams = new ModifiableSolrParams(params);
mParams.set("distrib", "false"); // We are the aggregator. mParams.set("distrib", "false"); // We are the aggregator.

View File

@ -519,21 +519,10 @@ public class TopicStream extends CloudSolrStream implements Expressible {
//System.out.println("Connected to zk an got cluster state."); //System.out.println("Connected to zk an got cluster state.");
Collection<Slice> slices = clusterState.getActiveSlices(this.collection); 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) { if (slices == null) {
throw new Exception("Collection not found:" + this.collection); throw new Exception("Collection not found:" + this.collection);
} }
}
Iterator<String> iterator = params.getParameterNamesIterator(); Iterator<String> iterator = params.getParameterNamesIterator();

View File

@ -40,7 +40,7 @@ public class ClusterState implements JSONWriter.Writable {
private final Integer znodeVersion; private final Integer znodeVersion;
private final Map<String, CollectionRef> collectionStates; private final Map<String, CollectionRef> collectionStates, immutableCollectionStates;
private Set<String> liveNodes; private Set<String> liveNodes;
/** /**
@ -67,6 +67,7 @@ public class ClusterState implements JSONWriter.Writable {
this.liveNodes = new HashSet<>(liveNodes.size()); this.liveNodes = new HashSet<>(liveNodes.size());
this.liveNodes.addAll(liveNodes); this.liveNodes.addAll(liveNodes);
this.collectionStates = new LinkedHashMap<>(collectionStates); this.collectionStates = new LinkedHashMap<>(collectionStates);
this.immutableCollectionStates = Collections.unmodifiableMap(collectionStates);
} }
@ -432,10 +433,12 @@ public class ClusterState implements JSONWriter.Writable {
this.liveNodes = liveNodes; 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() { public Map<String, CollectionRef> getCollectionStates() {
return collectionStates; return immutableCollectionStates;
} }
public static class CollectionRef { public static class CollectionRef {