[ 
https://issues.apache.org/jira/browse/SOLR-14700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18083979#comment-18083979
 ] 

David Smiley commented on SOLR-14700:
-------------------------------------

I strongly disagree here with the direction taken.  IMO streaming expressions 
should *insist* on a StreamContext for a deterministic / documented lifecycle 
so that these many expressions needn't support multiple lifecycle 
(context-less).  Many streaming expressions having checks like --  {{if 
(this.solrClientCache == null)}} then create one via {{new SolrClientCache()}}. 
 StreamContext should have insisted on a SolrClientCache ( SOLR-12718 ) and 
lifecycle managed by the caller so that these expressions don't have tedious 
code to deal with.  There are security implications as well but I won't get 
into that here.

> CloudSolrClient cannot be used without setting an explicit streamContext
> ------------------------------------------------------------------------
>
>                 Key: SOLR-14700
>                 URL: https://issues.apache.org/jira/browse/SOLR-14700
>             Project: Solr
>          Issue Type: Bug
>          Components: clients - java
>    Affects Versions: 8.6
>            Reporter: Mads Bondo Dydensborg
>            Priority: Minor
>             Fix For: 8.7, 9.0
>
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> A naive approach to using CloudSolrClient, such as on this page: 
> [http://joelsolr.blogspot.com/2015/04/the-streaming-api-solrjio-basics.html] 
> - will not work: opening the stream will throw an IOException with an 
> embedded NullPointerException.
> This took me a while to figure out, and I think it would be good to either 
> update the documentation or "fix" the constructor to set the needed 
> streamContext as appropriate.
> I found this snippet of code in TuppleStream.java, that seems to "almost" 
> work without a streamContext:
> {code:java}
> // line 127 in the sources to TuppleStream.java:
> public static List<String> getShards(String zkHost,
>                                        String collection,
>                                        StreamContext streamContext,
>                                        SolrParams requestParams)
> ...
> // line 135
> if(streamContext != null) {
>       shardsMap = (Map<String, List<String>>)streamContext.get("shards");
>     }
> ...
> // line 144
> CloudSolrClient cloudSolrClient =
>           
> Optional.ofNullable(streamContext.getSolrClientCache()).orElseGet(SolrClientCache::new).getCloudSolrClient(zkHost);
> {code}
> if streamContext is null in the last statement, a NullPointerException will 
> be thrown and open'ening the stream will fail.
> This took me way too long time to figure out.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to