Thanks Shawn so much.
I use SolrJ 6.4.0 and SolrCloud 6.4.0
The code is very simple:
I have Spring singleton bean to get one and only one instance of 
solrCloudClient as:

  
@Value("${zkHost.url:rws00dtr.us.oracle.com:2181,rws00dtr.us.oracle.com:2182,rws00dtr.us.oracle.com:2183}")
  private String zkHost;
  @Bean
  public CloudSolrClient solrClient() {
     Builder builder = new CloudSolrClient.Builder().withZkHost(zkHost);
    CloudSolrClient solrClient = builder.build();
    return solrClient;
  }

And I use this code for all functionalities, pivot, faceting, queries, indexing 
and so on.
The exception is intermittent and that is why I think it is related to 
thread-safe issue with the class.

Thanks
Mikhail

-----Original Message-----
From: Shawn Heisey [mailto:apa...@elyograg.org] 
Sent: 28 مارس, 2017 04:26 م
To: solr-user@lucene.apache.org
Subject: Re: Is CloudSolrClient thread-safe?

On 3/28/2017 8:13 AM, Mikhail Ibraheem wrote:
> I have a project with solr and spring. I am have only one instance of 
> CloudSolrClient at the context (singleton).
>
> This is because I believe that it should be only one instance to load balance 
> between the nodes.

Yes, the intent is to be fully threadsafe.  You should know that HttpClient, 
the class which the SolrClient implementations use under the hood, has a 
default limitation of only allowing two simultaneous connections to a given 
route, which I believe means a host/port combination.

Increasing this is possible, but it must be done by creating a custom 
HttpClient object.  Here's some code that I use to build such a client, then 
use that client to create an HttpSolrClient.  The same thing can be done with 
CloudSolrClient:

  RequestConfig rc = RequestConfig.custom().setConnectTimeout(15000)
      .setSocketTimeout(Const.SOCKET_TIMEOUT).build();
  httpClient = HttpClients.custom().setDefaultRequestConfig(rc)
     
.setMaxConnPerRoute(300).setMaxConnTotal(5000).disableAutomaticRetries()
      .build();
  client = new HttpSolrClient(serverBaseUrl, httpClient);

> I have big issue which doesn't occur all the times, it is intermittent:
>
> java.lang.ClassCastException: java.lang.String cannot be cast to 
> org.apache.solr.common.SolrDocumentList

That is odd.  What is the exact version of SolrJ that you are using, and the 
version of the SolrCloud cluster that it is talking to?  Can you share your 
SolrJ code?

Thanks,
Shawn

Reply via email to