SOLR-14700: avoid NPEs in TupleStream.getShards() when streamContext is null. (#1754)

This commit is contained in:
Christine Poerschke 2020-08-24 13:00:38 +01:00 committed by GitHub
parent f924225282
commit 4761dbabd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 10 deletions

View File

@ -192,6 +192,9 @@ Bug Fixes
* SOLR-14703: Fix edismax replacement of all whitespace characters with spaces (Yuriy Koval via Jason Gerlowski)
* SOLR-14700: Avoid NullPointerException in TupleStream.getShards() when streamContext is null.
(Mads Bondo Dydensborg, Christine Poerschke, Mike Drob)
Other Changes
---------------------

View File

@ -22,7 +22,6 @@ import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.Map;
@ -141,20 +140,34 @@ public abstract class TupleStream implements Closeable, Serializable, MapWriter
shards = shardsMap.get(collection);
} else {
//SolrCloud Sharding
CloudSolrClient cloudSolrClient =
Optional.ofNullable(streamContext.getSolrClientCache()).orElseGet(SolrClientCache::new).getCloudSolrClient(zkHost);
SolrClientCache solrClientCache = (streamContext != null ? streamContext.getSolrClientCache() : null);
final SolrClientCache localSolrClientCache; // tracks any locally allocated cache that needs to be closed locally
if (solrClientCache == null) { // streamContext was null OR streamContext.getSolrClientCache() returned null
solrClientCache = localSolrClientCache = new SolrClientCache();
} else {
localSolrClientCache = null;
}
CloudSolrClient cloudSolrClient = solrClientCache.getCloudSolrClient(zkHost);
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
ClusterState clusterState = zkStateReader.getClusterState();
Slice[] slices = CloudSolrStream.getSlices(collection, zkStateReader, true);
Set<String> liveNodes = clusterState.getLiveNodes();
ModifiableSolrParams solrParams = new ModifiableSolrParams(streamContext.getRequestParams());
RequestReplicaListTransformerGenerator requestReplicaListTransformerGenerator;
final ModifiableSolrParams solrParams;
if (streamContext != null) {
solrParams = new ModifiableSolrParams(streamContext.getRequestParams());
requestReplicaListTransformerGenerator = streamContext.getRequestReplicaListTransformerGenerator();
} else {
solrParams = new ModifiableSolrParams();
requestReplicaListTransformerGenerator = null;
}
if (requestReplicaListTransformerGenerator == null) {
requestReplicaListTransformerGenerator = new RequestReplicaListTransformerGenerator();
}
solrParams.add(requestParams);
RequestReplicaListTransformerGenerator requestReplicaListTransformerGenerator =
Optional.ofNullable(streamContext.getRequestReplicaListTransformerGenerator()).orElseGet(RequestReplicaListTransformerGenerator::new);
ReplicaListTransformer replicaListTransformer = requestReplicaListTransformerGenerator.getReplicaListTransformer(solrParams);
for(Slice slice : slices) {
@ -170,10 +183,15 @@ public abstract class TupleStream implements Closeable, Serializable, MapWriter
shards.add(sortedReplicas.get(0).getCoreUrl());
}
}
if (localSolrClientCache != null) {
localSolrClientCache.close();
}
}
Object core = streamContext.get("core");
if (streamContext != null && streamContext.isLocal() && core != null) {
shards.removeIf(shardUrl -> !shardUrl.contains((CharSequence) core));
if (streamContext != null) {
Object core = streamContext.get("core");
if (streamContext.isLocal() && core != null) {
shards.removeIf(shardUrl -> !shardUrl.contains((CharSequence) core));
}
}
return shards;

View File

@ -2716,4 +2716,11 @@ public void testParallelRankStream() throws Exception {
return pstream;
}
public void testCloudSolrStreamWithoutStreamContext() throws Exception {
SolrParams sParams = StreamingTest.mapParams("q", "*:*", "fl", "id", "sort", "id asc");
try (CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams)) {
stream.open();
}
}
}